File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes exception getting while running a Hibernate program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "exception getting while running a Hibernate program" Watch "exception getting while running a Hibernate program" New topic
Author

exception getting while running a Hibernate program

Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
I running a basic program which has Hibernate concept and i am getting an exception as follows :

------------ output -------------------

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
at com.vaannila.student.Main.main(Main.java:16)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:120)
at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:10)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
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)
... 3 more

-------------------------- output -------------------------------------------------


Perform for today. Adapt for tomorrow.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are missing one (or more) dependencies. Check the Hibernate website for a list of the jar files you need.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

At the very least you're missing the Apache Commons Logging library.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
David Newton wrote:At the very least you're missing the Apache Commons Logging library.


if some library is missing it should have been given a compilation error.

But strange thing is that its not giving me any compilation error.

what I am suppose to do for this problem?

Details are as follows :



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



now when i click on first exception in output its taking me to the LINE 1 of the above code... some ExceptionInInitializerError like that ...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I think you misunderstand how Java works. You are missing, at the very least, the Apache Commons Logging library, as indicated by the error message. You (presumably) are nit compiling Hibernate. Hibernate has a dependency on commons-logging. The code *you* have written does not, so when you compile *your* code, you don't need it.

But your application depends both on your code, *and* on Hibernate: thus your application has a dependency on commons-logging. This is a "transitive dependency". The error message is quite clear: you are missing commons-logging. You may be missing other dependencies as well.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
This is the hibernate config file, is this any thing to with this problem ?



Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No. You are missing some Jar files Hibernate depends on. Check the Hibernate documentation to see what the dependencies are. At the very least (as David points out) you are missing commons logging.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Paul Sturrock wrote:No. You are missing some Jar files Hibernate depends on. Check the Hibernate documentation to see what the dependencies are. At the very least (as David points out) you are missing commons logging.


Sorry but , thats what i want to tell you that i am missing some jar files then Eclipse should show me compile time Error. Isn't it?

But its not showing me compile time error.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No.

You're not compiling Hibernate, which is what has the dependency.

You have a fundamental misunderstanding about how Java works and when/how dependency resolution occurs. You are missing at *least* Commons Logging.

We can go back and forth on this all you want, but the answer isn't going to change. I don't know *why* you don't believe us, but it'd be quicker for you if you did.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Got it.

It is transitive dependancy which compiler doesn't catch.

Is it so?
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Rahul Shilpakar wrote:But its not showing me compile time error.

Yes. It is not showing and it will only if you're compiling hibernate source code.


If you are not laughing at yourself, then you just didn't get the joke.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception getting while running a Hibernate program
 
Similar Threads
error
Error:java.lang.NoClassDefFoundError: javax/persistence/EntityList
Initial SessionFactory creation failed.java.lang.ExceptionInInitializerError
jar error
error during encryption of xml file.....pls help