-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: ExceptionInInitializerError in new Configuration()
PostPosted: Sun Mar 07, 2010 2:01 pm 
Newbie

Joined: Sun Mar 07, 2010 1:51 pm
Posts: 6
Hello everybody,

I have a problem on the construction of my Configuration object. This exception is thrown :

java.lang.ExceptionInInitializerError
org.hibernate.cfg.Configuration.reset(Configuration.java:217)
org.hibernate.cfg.Configuration.<init>(Configuration.java:197)
org.hibernate.cfg.Configuration.<init>(Configuration.java:201)
MyProject.HibernateUtils.getSession(HibernateUtils.java:15)
MyProject.MyRepository.getAll(MyRepository.java:35)
MyProject.Controller.HomePageController.handleRequest(HomePageController.java:20)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

caused by

java.lang.NullPointerException
org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
org.hibernate.cfg.Environment.<clinit>(Environment.java:575)
org.hibernate.cfg.Configuration.reset(Configuration.java:217)
org.hibernate.cfg.Configuration.<init>(Configuration.java:197)
org.hibernate.cfg.Configuration.<init>(Configuration.java:201)
MyProject.HibernateUtils.getSession(HibernateUtils.java:15)
MyProject.MyRepository.getAll(MyRepository.java:35)
MyProject.Controller.HomePageController.handleRequest(HomePageController.java:20)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

And then, if i try to update my page, i got this one :

java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.Environment
org.hibernate.cfg.Configuration.reset(Configuration.java:217)
org.hibernate.cfg.Configuration.<init>(Configuration.java:197)
org.hibernate.cfg.Configuration.<init>(Configuration.java:201)
MyProject.HibernateUtils.getSession(HibernateUtils.java:15)
MyProject.MyRepository.getAll(MyRepository.java:35)
MyProject.Controller.HomePageController.handleRequest(HomePageController.java:20)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Maybe i am missing a jar, i search on google and on this forum but i did not found anything.
Thank you for your help and excuse my poor english.


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Sun Mar 07, 2010 9:14 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Maybe you application failed to load hibernate.cfg.xml. Where do you put that file? How do you load that file?


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 4:29 am 
Newbie

Joined: Sun Mar 07, 2010 1:51 pm
Posts: 6
That is what I thought first. So i try to configure hibernate by the code. I have something like :

Configuration cfg = new Configuration();
cfg.addResource("Something.hbm.xml");
cfg.setProperty(....)

And the application fails on the constructor : Configuration cfg = new Configuration();

Thank you.


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 5:43 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
do you put your hbm.xml in the package?


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 6:42 am 
Newbie

Joined: Sun Mar 07, 2010 1:51 pm
Posts: 6
I will check as soon as possible if the hbm.xml is well accessible by my HibernateUtils.java, but it is in the same project so I think it's accessible.
What I cannot figure is why the application fails on Configuration cfg = new Configuration(); and not cfg.addResource("Something.hbm.xml"); if the probleme is on the hbm.xml.

Thank you for your answer
I'll check that tonight


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 10:00 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
try using this code
Code:
Configuration cfg = new Configuration().configure();


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 10:32 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I suspect that this is a classloader issue. Where have you placed your hibernate3.jar file?


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 2:45 pm 
Newbie

Joined: Sun Mar 07, 2010 1:51 pm
Posts: 6
I think you're right nordborg, I try to use my configuration with a JUnit Test cas and it works fine, but in my web project, always the same error.
I have placed the hibernate3.jar (and all the jar required for hibernate) in a project named HRepository (where I have my HibernateUtil.java, my mappings files and all my access to the base).
But the web part of my application is in another project MyWebProject which has the HRepository project in his build path. This project is linked with Tomcat. I linked the jar as source on the Tomcat configuration (Open launch configuration > Source) but maybe I am doing something wrong.
Do you know how i can be sure that it's the hibernate3.jar that is missing (and not an additional jar) ? And do you know I can link the jar to be used in my servlet?

Thank you for your answers

Edit :

I tried to remove the hibernate3.jar from the Tomcat configuration and i get another error :org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


caused by

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
HRepository.HibernateUtils.getSession(HibernateUtils.java:15)
HRepository.News.HNewsRepository.getAll(HNewsRepository.java:35)
MyWebProject.Controller.HomePageController.handleRequest(HomePageController.java:20)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


So obviously it's not the hibernate3.jar which is missing but maybe something else. What are all the jar needed to make hibernate work fine?


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 3:16 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Tomcat can find the hibernate3.jar. The error is coming from one of the Hibernate classes. But I think those classes are not loaded by the correct class loader. Tomcat has a rather complex class loading implementation and you are more or less required to put your jar files in the 'WEB-INF/lib' folder of the project. Anywhere else may or may not work depending on the application is doing.

I don't understand your setup. Are you running Tomcat from within a development environment? I have never tried that.

Unless line numbers have changed the following piece of code is line 167 in ConfigHelper:

Code:
stream = Environment.class.getClassLoader().getResourceAsStream( stripped );


The only possible cause for a NullPointerException on this line is if getClassLoader() returns null, which is possible if the class was loaded by the bootstrap class loader. But if configured correctly hibernate should not be loaded by the bootstrap class loader, but by one of Tomcat's class loaders. In any case, line 167 is near the end of the method and is only reached if the file it tries to load hasn't been found already. It is very likely that it is looking for '/hibernate.properties' in this case.

Don't know if this makes sense or if it helps you track down the problem....


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Mon Mar 08, 2010 4:55 pm 
Newbie

Joined: Sun Mar 07, 2010 1:51 pm
Posts: 6
Yes I use Tomcat directly integrated in eclipse in order to have the project deployed in "real time". I cannot work on my project know but I will try to put all the jar in my WEB-INF in order to avoid the Tomcat problems, and retry to use hibernte.cfg.xml to avoid the reach of the line 167.

Thank you for your help by the way.


Top
 Profile  
 
 Post subject: Re: ExceptionInInitializerError in new Configuration()
PostPosted: Fri Mar 12, 2010 4:38 am 
Newbie

Joined: Sun Mar 07, 2010 1:51 pm
Posts: 6
Thank you for your help, it's now working fine.

You were right, the problem was linked with Tomcat and the organisation of projects and jar references. I downloaded Eclipse WTP which permit to organize references between J2EE project. Now it's all working fine.

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.