Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate project configuration in eclipse3.5 and netbeans6.8

 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, i am at my wits end for the last few days. I am working out the hibernate example provided in http://www.mastertheboss.com/en/hibernate/182-hibernate-tutorial.html . In eclipse its always coming as ExceptionInitializerError and null pointer exception. But with the netbeans its perfectly working out and i am able to insert the data to the mysql table. I am using the same Hibernate 3.3 lib and the project structure is also same in both the ides . If anybody has this strange experience please help me. Thank you.
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hem kumar wrote:Hi all, i am at my wits end for the last few days. I am working out the hibernate example provided in http://www.mastertheboss.com/en/hibernate/182-hibernate-tutorial.html . In eclipse its always coming as ExceptionInitializerError and null pointer exception. But with the netbeans its perfectly working out and i am able to insert the data to the mysql table. I am using the same Hibernate 3.3 lib and the project structure is also same in both the ides . If anybody has this strange experience please help me. Thank you.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34391
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hem,
Can you post the stack trace of the exception? There are a few things in that tutorial that could cause a Null Pointer.
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jeane, here are the error stack trace from the eclipse environment-

Initial SessionFactory creation failed.java.lang.ExceptionInInitializerError
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.sample.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:18)
at com.sample.TestPerson.main(TestPerson.java:14)
Caused by: java.lang.ExceptionInInitializerError
at com.sample.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:13)
... 1 more
Caused by: java.lang.NullPointerException
at org.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
... 2 more


Here is the project structure with the lib used-



ProjectStructure.PNG
[Thumbnail for ProjectStructure.PNG]
The Project Structure
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The strange thing which i not able to understand is, the same project with the same structure and lib configuration except that the hibernate.cfg.xml is in the default package instead of this conf folder as in eclipse is working perfectly without any errors in netbeans 6.8.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34391
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hem,
The stack trace is telling you it can't find the hibernate config file. Meaning it is not in the classpath. Why don't you have it in the default package like you do in NetBeans since that works?
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne

i have tried all sort of project configuration. Kept that hibernate.cfg.xml in the root / default src package and its also getting compiled and copied into the bin directory. But still am having the same error. Thanks for your time.

I am thinking of using NetBeans instead of wasting time in eclipse

Anyway this is the stack trace ->

Initial SessionFactory creation failed.java.lang.ExceptionInInitializerError
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.sample.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:18)
at com.sample.TestPerson.main(TestPerson.java:14)
Caused by: java.lang.ExceptionInInitializerError
at com.sample.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:14)
... 1 more
Caused by: java.lang.NullPointerException
at org.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
... 2 more

And here is the new structure-
ProjectStructure.PNG
[Thumbnail for ProjectStructure.PNG]
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats an exception coming out of your logger. Have a look at the versions you are using. api-1.5.8 with an implementation 1.5.2. Try updating the last jar-File in your screenshot to 1.5.8.
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i changed the implementation to 1.5.8, but still there exists the same error. Its not able to read my hibernate.cfg.xml file. I dont know why?
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem has been solved sometimes ago. So instead of keeping the hibernate.cfg.xml in any folder, we should keep it in the source folder which can be found if right clicked on the project name in eclipse. By that eclipse will automatically load it into classpath and the errors like class not found and InitializerExceptions wont occur. Thank you all.
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hem kumar wrote:The problem has been solved sometimes ago. So instead of keeping the hibernate.cfg.xml in any folder, we should keep it in the source folder which can be found if right clicked on the project name in eclipse. Below is a screen shot for clarification. By that eclipse will automatically load it into classpath and the errors like class not found and InitializerExceptions wont occur. Thank you all.
ScreenShot001.png
[Thumbnail for ScreenShot001.png]
Where to keep the hibernate.config.xml file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic