This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes hibernate project configuration in eclipse3.5 and netbeans6.8 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate project configuration in eclipse3.5 and netbeans6.8" Watch "hibernate project configuration in eclipse3.5 and netbeans6.8" New topic
Author

hibernate project configuration in eclipse3.5 and netbeans6.8

hem kumar
Ranch Hand

Joined: Sep 05, 2005
Posts: 97
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.


.....For Every Problem There Is a Solution.....
Regards, Hem
hem kumar
Ranch Hand

Joined: Sep 05, 2005
Posts: 97
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

Hem,
Can you post the stack trace of the exception? There are a few things in that tutorial that could cause a Null Pointer.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
hem kumar
Ranch Hand

Joined: Sep 05, 2005
Posts: 97
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-






[Thumbnail for ProjectStructure.PNG]

hem kumar
Ranch Hand

Joined: Sep 05, 2005
Posts: 97
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

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

Joined: Sep 05, 2005
Posts: 97
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-


[Thumbnail for ProjectStructure.PNG]

Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
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

Joined: Sep 05, 2005
Posts: 97
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

Joined: Sep 05, 2005
Posts: 97
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

Joined: Sep 05, 2005
Posts: 97
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.



[Thumbnail for ScreenShot001.png]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate project configuration in eclipse3.5 and netbeans6.8