Hibernate.cfg.xml not found after deploy the web app to heroku - java

After deploying a web application with maven to heroku cloud, I get log error:
app[web.1]: org.hibernate.HibernateException: hibernate.cfg.xml not found.
The web application running locally correctly, but on the cloud not.
This is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/todoitemsdb
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping class="il.ac.hit.model.User" resource="todoitems.xml"/>
<mapping class="il.ac.hit.model.ToDoItem" resource="users.xml"/>
</session-factory>
</hibernate-configuration>
What can I do?

Make sure that the hibernate.cfg.xml is bundled into your jar like this:
your-app.jar\hibernate.cfg.xml
That's where Hibernate tries to locate the configuration file.

I had my hibernate.cfg.xml under resources under a folder config
Changing the below line
cfg.configure("./config/hibernate.cfg.xml");
to
cfg.configure("config/hibernate.cfg.xml");
worked.

Related

printing DEBUG log in console, how to disable it

getting many debug printing in cosole how to disable it?
00:00:39.293 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
tryed to write in app.properties logging.level.root=info
and -Dlogging.level.org.springframework=INFO in run/debug configuration->program arguments
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="connection.username">user</property>
<property name="connection.password">user</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL10Dialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping class="dmdev.lesson.entity.User"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hibernate.hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
what im doing wrong?
Looks like you are using JBoss; it uses Log4J as its logger.
You will need to configure JBoss/Log4J to change the log level. That can be done through JBoss's CLI, Admin Page, or by modifying standalone.xml.
This links should help:
JBoss AS 7.2 - Logging Configuration
Configure Root Logger
Another SO Answer

Source button missing from hibernate configuration XML file in eclipse

When I created a hibernate Configuration file, eclipse is not able to display the source code as there is no source button at the bottom of the page. I can able to navigate between Session Factory and Security whereas Source button is missing. How can fix this issue? I have attached the picture below for reference.
Hibernate Configuration XML File
make your own one and add the below:
fileName is: hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Book</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="book.hbm.xml" />
</session-factory>
</hibernate-configuration>
And if you want to read more about it go here

Bind datasource to persistence on Intellij fails on resolve column

I'm starting learing how to use IntelliJ, and I'm trying to link my persistence to my datasource.
I've read here on SO how to do that, and now I've binded my persistence to my datasource successfully: I can run queries on database, and i can browse my persistence.
This is the db (MSSQL):
This is the persistence:
And this is the assignment:
The problem is that I'm still getting error on my class, looks like is not able to link to the datasource, and is giving me the error "Cannot resolve column" (not only on ID column, but on all columns):
The application is running fine, so the problem is only related to some wrong intellij configuration, but I can't find where the problem is.
This is my hibernate.cfg.xml (there are more tables, I've left only the one in the example):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="Artemide">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<!-- Configurazione maven-->
<property name="hibernate.connection.password">${hibernate.password}</property>
<property name="hibernate.connection.username">${hibernate.username}</property>
<property name="hibernate.connection.url">${hibernate.connection.url}</property>
<property name="hibernate.default_catalog">${hibernate.default_catalog}</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">true</property>
<mapping class="xx.xx.xx.database.pojo.Categoria"/>
</session-factory>
</hibernate-configuration>
Thanks!

Eclipse doesn't show correct tables in Hibernate config

I'm making a new project with Hibernate.
I have some problems configure hibernate correctly in my Eclipse environment.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">XXXXX</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost/Framework</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.default_schema">Framework</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
My Eclipse environment only sees the master database instead of my Framework database. Can someone help me with this?
The database was not correctly configured. The user didn't have the correct permissions. After fixing this it works.

how to map classes in hibernate using the class attribute?

I have a problem in my maven project
click the links below to see it
I added this to my hibernate.cfg but didn't work
<mapping package="com.redpass.entities"/>
<mapping class="com.redpass.entities.MyReference"/>
console error
Project Explorer
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/avocatbd</property>
<property name="connection.username">root</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- <mapping package="com.redpass.entities"/>
<mapping class="com.redpass.entities.MyReference"/> -->
</session-factory>
</hibernate-configuration>
I should add this:
configuration.configure("hibernate.cfg.xml");
return configuration
.buildSessionFactory(new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.build());
to my HibernateUtil Class to tell that we want to configure using the hibernate.cfg.xml file and map the classes like this:
<mapping class="com.redpass.entities.Partie"/>
<mapping class="com.redpass.entities.Societe"/>

Categories

Resources