aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate.cfg.xml problem - not able to run the java project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate.cfg.xml problem - not able to run the java project" Watch "Hibernate.cfg.xml problem - not able to run the java project" New topic
Author

Hibernate.cfg.xml problem - not able to run the java project

BhanuChandar Challa
Greenhorn

Joined: Nov 05, 2012
Posts: 7
Please Help me in below the issue.

I have tried to create a simple java project which will store the UserDetails data into the PostgreSQL database by using Hibernate.
But i am getting the below error when i tried to run the application.

CONSOLE:
-------------------------------------------------------------------------------------------
Nov 05, 2012 3:21:28 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 05, 2012 3:21:28 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
Nov 05, 2012 3:21:28 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Nov 05, 2012 3:21:28 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Nov 05, 2012 3:21:28 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Nov 05, 2012 3:21:28 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1953)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1934)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1914)
at org.chandu.hibernate.HibernateTest.main(HibernateTest.java:21)
---------------------------------------------------------------------------------------------------------------

My hibernate.cfg.xml file is:
---------------------------------------------------------------------------------------------------------------
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">dbc:postgresql://localhost:5432/hibernatedb</property>
<property name="connection.username">postgres</property>
<property name="connection.password">chandu</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">Create</property>

<mapping resource="org.javabrains.chandu.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
-----------------------------------------------------------------------------------------------------------------------

I am using hibernate 4.1.8 for this project. If it is the problem with <!DOCTYPE element in hibernate.cfg.xml, Please help me to edit it.


Thanks in Advance,
Bhanu Chandar.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

From the error message
...Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found

The configuration file is not found. Where have you kept hibernate.cfg.xml file.
I hope this thread will help you.

Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
BhanuChandar Challa
Greenhorn

Joined: Nov 05, 2012
Posts: 7
I kept the hibernate.cfg.xml file in the classpath only. Please find the attached screenshot for project tree.


[Capture.PNG]

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Are you using any kind of build tool? If yes, please check if the file is moved to build folder after compilation
BhanuChandar Challa
Greenhorn

Joined: Nov 05, 2012
Posts: 7
No I am not using any build tool. Please find the detailed tree.


[Capture.PNG]

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

How are you building your application? Where does the .class files resides? Put your configuration file directly inside the 'src' folder.
I would suggest you to please go though the link provided earlier along with the this Google.
Thanks.
BhanuChandar Challa
Greenhorn

Joined: Nov 05, 2012
Posts: 7
I am very new to java envi, so please igonre my mistakes.
---------------------------------------------------------------------

After i moving hibernate.cfg.xml file to src location, I got below the new error.

Nov 05, 2012 4:36:50 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 05, 2012 4:36:50 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
Nov 05, 2012 4:36:50 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Nov 05, 2012 4:36:50 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Nov 05, 2012 4:36:50 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Nov 05, 2012 4:36:50 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Nov 05, 2012 4:36:51 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Nov 05, 2012 4:36:51 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: org.javabrains.chandu.dto.UserDetails
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: org.javabrains.chandu.dto.UserDetails not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:728)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2115)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2087)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2067)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2020)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1935)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1914)
at org.chandu.hibernate.HibernateTest.main(HibernateTest.java:21)
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Are you creating hibernate mappings using annotations in the UserDetails class?
If so, then you have to map it accordingly in hibernate.cfg.xml file.

Replace this


with


BhanuChandar Challa
Greenhorn

Joined: Nov 05, 2012
Posts: 7
Thanks sumeet. Now I am able to run my java project. Thanks for your help and valuable time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate.cfg.xml problem - not able to run the java project