Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception getting while running a Hibernate program

 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 -------------------------------------------------
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing one (or more) dependencies. Check the Hibernate website for a list of the jar files you need.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the very least you're missing the Apache Commons Logging library.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the hibernate config file, is this any thing to with this problem ?



 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.

It is transitive dependancy which compiler doesn't catch.

Is it so?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic