• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
BhanuChandar Challa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I kept the hibernate.cfg.xml file in the classpath only. Please find the attached screenshot for project tree.
Capture.PNG
[Thumbnail for Capture.PNG]
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I am not using any build tool. Please find the detailed tree.
Capture.PNG
[Thumbnail for Capture.PNG]
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks sumeet. Now I am able to run my java project. Thanks for your help and valuable time.
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic