• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

configuration in hibernate problem

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not getting that how did Hibernate know where the configuration file was located?

I am trying to practice hibernate using core java only. I created my client class main class, hibernate.cfg.xml, o.hbm.xml, and POJO class having getter setters need for mapping.

My code:



Now, i also tried the different which replace LINE 1

i.e. .configure("conf/hibernate.cfg.xml")



My Output is an Exception in between LINE 1 to 3
*****************************

You are in main method boss..
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/Attribute
at hyber.GoodHyber.main(GoodHyber.java:38)
Caused by: java.lang.ClassNotFoundException: org.dom4j.Attribute
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 1 more
******************************

please guid me where am i wrong? Even though i have correctly mentioned the hibernate.cfg.xml file path.

besides this I am not providing any VM arguments to my main class through eclipse. also my properties are with in hibernate.cfg.xml file itslef as i read in book that we only need to give relative path of hibernate.cfg.xml file as configure method argument. :roll:
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are missing jar fromyour classpath.
the missing jar is dom4j

look at the exception:
org/dom4j/Attribute
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply.

As you suggested i added the dom4j and commans-logging which was required but still its giving me exception

-----------------
Output:
-----------------
You are in main method boss..
Aug 8, 2008 5:44:42 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.3
Aug 8, 2008 5:44:42 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Aug 8, 2008 5:44:42 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Aug 8, 2008 5:44:42 AM net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: conf/hibernate.cfg.xml
Aug 8, 2008 5:44:42 AM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: conf/hibernate.cfg.xml
Aug 8, 2008 5:44:42 AM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
WARNING: conf/hibernate.cfg.xml not found
net.sf.hibernate.HibernateException: conf/hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:849)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:873)
at hyber.GoodHyber.main(GoodHyber.java:38)


What may be the problem. How did Hibernate know where we keep the configuration file?

I wonder how can i do this in Eclipse?
I am using Eclipse GANYMEDE.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate by default looks for "hibernate.cfg.xml" file in the class path of the application. So make sure you have that file in your class path.

If hibernate finds hibernate configuration properties file and xml files, xml file settings will override the properties file.

So please make sure you have the .xml file in your class path.

In your code you have specified "conf/hibernate.cfg.xml", if you dont have the "conf" directory, just try with "hibernate.cfg.xml".
[ October 19, 2008: Message edited by: Kadle Rajesh ]
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to set class path in COMMAND PROMPT and also runs my MAIN class in the same.

cmd.exe
------------
set path= //something
set classpath= absolute path to cfg.xml file (including conf file name); also my project jar; and also supporting jars;

java hyber.Goodhyber

Output
------------
:
:
WARNING : can not find the hibernate.cfg.xml
:
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys please help me to solve it. What might be wrong with my program?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is hibernate.cfg.xml deployed to? It needs to be in you class files, or in your jar file in the package conf. Is it?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic