This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

hibernate.cfg.xml location for Eclipse project

 
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic