-->
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.  [ 4 posts ] 
Author Message
 Post subject: ExceptionInInitializerError
PostPosted: Sun May 01, 2005 12:12 pm 
Newbie

Joined: Sun May 01, 2005 12:04 pm
Posts: 6
Location: Munich, Germany
Hi there,

I am about to set up a simple JavaServer Faces Web Application and integrated hibernate quite successfully so far. My problem now is that (after doing some tests without web context) I need to run hibernate in the web application.

I am using the HibernateUtil class as it is explained in the tutorial. I know that this might not be perfect, but I would like to get it running and then think about even better solutions.

My current error when I try to access a simple Servlet that should print out the number of "Images" in my images table: browser output:

java.lang.ExceptionInInitializerError
de.flavor.suevia.web.util.HibernateUtil.<clinit>(Unknown Source)
de.flavor.suevia.web.HibernateTestServlet.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Before this error I had problems with the connection to my mysql database, I think this was because the hibernate.properties was in the classpath of the web appliation. After I deleted this properties file from the classpath, I now got this error.

The hibernate.cfg.xml is in my web classpath, so this should work.

Do you have any ideas?

Thank you!

Below is the simple servlet code that I am trying to run.

Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

Criteria criteria = session.createCriteria(Image.class);
List images = criteria.list();
log.debug("Amount of images found: " + images.size());
response.getOutputStream().println("I've found " + images.size() + " images. It works!");

tx.commit();
HibernateUtil.closeSession();


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 01, 2005 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Every example of HibernateUtil has a comment in it: "Log this exception, it might get swallowed". You have removed or ignored it.


Top
 Profile  
 
 Post subject: Another Problem: java.lang.NoClassDefFoundError: net/sf/ehca
PostPosted: Sun May 01, 2005 3:50 pm 
Newbie

Joined: Sun May 01, 2005 12:04 pm
Posts: 6
Location: Munich, Germany
I now got another error. I decide to create the configuration myself like this:

// Create the SessionFactory
Configuration cfg = new Configuration();
cfg.addResource("de/flavor/suevia/web/om/Product.hbm.xml");
cfg.addResource("de/flavor/suevia/web/om/Accessory.hbm.xml");
cfg.addResource("de/flavor/suevia/web/om/Image.hbm.xml");
cfg.addResource("de/flavor/suevia/web/om/PDF.hbm.xml");
cfg.addResource("de/flavor/suevia/web/om/ProductAccessory.hbm.xml");
cfg.addResource("de/flavor/suevia/web/om/TextElement.hbm.xml");
cfg.setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/sueviaweb");
cfg.setProperty("show_sql", "false");
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLMyISAMDialect");
sessionFactory = cfg.buildSessionFactory();


That works fine so far. (I think Hibernate now can find the hbm files and creates the mappings). But this is the exception I get in the catalona.out

Caused by: java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:1618)
at java.lang.Class.getConstructor0(Class.java:1930)
at java.lang.Class.newInstance0(Class.java:278)
at java.lang.Class.newInstance(Class.java:261)
at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:262)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:184)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)

Do I miss a jar file? I am using tomcat 5.5.7 and followed the tomcat tutorial online. I think only my mysql driver should be added to the common/lib, everything else is in the WEB-INF/lib - is this still right for Tomcat 5.5.7 ?

I got a few testcases that used hibernate.properties to configure the sessionfactory. there, everything worked fine.

any help is appreciated!

Cheers\
Sven


Top
 Profile  
 
 Post subject: got it...
PostPosted: Sun May 01, 2005 3:57 pm 
Newbie

Joined: Sun May 01, 2005 12:04 pm
Posts: 6
Location: Munich, Germany
the ehcache jar was missing :-) an obvious one.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.