Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate.cfg.xml location for Eclipse project

 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am trying to learn hibernate. My IDE is Eclipse.

------------------------------------------------------------------------------------

Sep 25, 2009 1:57:04 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Hibernate 3.3.0.CR1
Sep 25, 2009 1:57:04 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: hibernate.properties not found
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Bytecode provider name : cglib
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: configuring from resource: /hibernate.cfg.xml
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Configuration resource: /hibernate.cfg.xml
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Reading mappings from resource : de/laliluna/example/Honey.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at de.laliluna.example.TestExample.createHoney(TestExample.java:96)
at de.laliluna.example.TestExample.main(TestExample.java:32)
Caused by: org.hibernate.MappingNotFoundException: resource: de/laliluna/example/Honey.hbm.xml not found

------------------------------------------------------------------------------------

What should be the location of the xml files [Honey.hbm.xml ] and [hibernate.cfg.xml]

I have tried to put the files under the project folder i.e. FirstHibernateExample folder but it does not work.

My project location in Eclipse is as follows: D:\eclipse-jee-europa-win32(2)\eclipse\FirstHibernateExample.

Where should I put the xml files so that the jvm can find them.

Priety.
 
Jeroen Bs
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I read the error output correctly:

Sep 25, 2009 1:57:04 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Hibernate 3.3.0.CR1
Sep 25, 2009 1:57:04 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: hibernate.properties not found
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Bytecode provider name : cglib
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: configuring from resource: /hibernate.cfg.xml
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Configuration resource: /hibernate.cfg.xml
Sep 25, 2009 1:57:05 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Reading mappings from resource : de/laliluna/example/Honey.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at de.laliluna.example.TestExample.createHoney(TestExample.java:96)
at de.laliluna.example.TestExample.main(TestExample.java:32)
Caused by: org.hibernate.MappingNotFoundException: resource: de/laliluna/example/Honey.hbm.xml not found


You can see that it can read the hibernate.cfg.xml file and then fails when reading Honey.hbm.xml. It expects the xml the be in the path: de/laliluna/example/ so you have to check the path.
If i'm correct (and I dont know for sure because I only use annotations and no XML) that the xml files should be placed in the META-INF (..\src\java\META-INF) just like the persistence.xml.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeroen Bs ,

Thanks for the reply.

The xml files are now getting read. hibernate.cfg.xml file is now put in the "bin" directory under the project folder and the Honey.hbm.xml file is under one of the packages under the scr folder.

Still how can I put them in the META-INF directory. I am only running the code from Eclipse and have not created a deployable.

Also a new error is showing up when attempting to connect to the deryby database.
I have mentioned the following connection url in the hibernate.cfg.xml file:
<property name="connection.url">jdbc:derby://localhost:1527/myDB;</property>
which should be correct url since I use the same command from the derby console to connect to the database.

The error is a follows:
-------------------------------------------------------------
Sep 25, 2009 10:35:53 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/myDB;
Sep 25, 2009 10:35:53 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: connection properties: {user=me, password=****}
Sep 25, 2009 10:35:57 PM org.slf4j.impl.JCLLoggerAdapter warn
WARNING: Could not obtain connection metadata
java.sql.SQLException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown
-------------------------------------------------------------

What should I do?

Priety.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like it can't connect on thet port. This may be due to a firewall or so.

Priety Sharma wrote:Hi Jeroen Bs ,

Thanks for the reply.

The xml files are now getting read. hibernate.cfg.xml file is now put in the "bin" directory under the project folder and the Honey.hbm.xml file is under one of the packages under the scr folder.

Still how can I put them in the META-INF directory. I am only running the code from Eclipse and have not created a deployable.

Also a new error is showing up when attempting to connect to the deryby database.
I have mentioned the following connection url in the hibernate.cfg.xml file:
<property name="connection.url">jdbc:derby://localhost:1527/myDB;</property>
which should be correct url since I use the same command from the derby console to connect to the database.

The error is a follows:
-------------------------------------------------------------
Sep 25, 2009 10:35:53 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/myDB;
Sep 25, 2009 10:35:53 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: connection properties: {user=me, password=****}
Sep 25, 2009 10:35:57 PM org.slf4j.impl.JCLLoggerAdapter warn
WARNING: Could not obtain connection metadata
java.sql.SQLException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown
-------------------------------------------------------------

What should I do?

Priety.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priety Sharma wrote:
Also a new error is showing up when attempting to connect to the deryby database.
I have mentioned the following connection url in the hibernate.cfg.xml file:
<property name="connection.url">jdbc:derby://localhost:1527/myDB;</property>
which should be correct url since I use the same command from the derby console to connect to the database.

The error is a follows:
-------------------------------------------------------------
Sep 25, 2009 10:35:53 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/myDB;
Sep 25, 2009 10:35:53 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: connection properties: {user=me, password=****}
Sep 25, 2009 10:35:57 PM org.slf4j.impl.JCLLoggerAdapter warn
WARNING: Could not obtain connection metadata
java.sql.SQLException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown
-------------------------------------------------------------

What should I do?

Make sure the Database is up and running, and are you able to connect through plain JDBC ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic