-->
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: SessionFactoryImpl 2nd call - java.lang.NoClassDefFoundError
PostPosted: Fri Dec 17, 2004 3:41 pm 
Newbie

Joined: Mon Nov 22, 2004 1:04 pm
Posts: 5
Location: Denver, CO
I am trying to initialize hibernate from a startup servlet within Tomcat. The following line of code
QUERY_KEY_FACTORY = (QueryCacheKeyFactory) KeyFactory.create(QueryCacheKeyFactory.class);

in
package net.sf.hibernate.impl.SessionFactoryImpl

semms to be called twice after
sessionFactory = new Configuration().configure().buildSessionFactory();

The first time it executes fine, the next time it blows up on finding the KeyFactory and I get a java.lang.NoClassDefFoundError

I am using Eclipse to attach a debugger to tomcat, and have downlowded the cglib src jar. I can step into the jar the first time it is called, but not the second.

I have checked the required libraries in the readme.txt file and I have all the required, and some of the optional that I was not sure about.

I am stuck any help would be greatly appreciated.

Thanks,
Chad

Hibernate version:
2.1.6

Code between sessionFactory.openSession() and session.close():
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {

Full stack trace of any exception that occurs:
java.lang.RuntimeException: Configuration problem: null
at gov.fbi.vicap.dal.HibernateSessionManager.<init>(HibernateSessionManager.java:34)
at gov.fbi.vicap.init.VicapFactoryInit.init(VicapFactoryInit.java:12)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
Caused by: java.lang.NoClassDefFoundError
at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:236)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:791)
at gov.fbi.vicap.dal.HibernateSessionManager.<init>(HibernateSessionManager.java:25)
... 19 more

2004-12-17 11:44:46 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]

Name and version of the database you are using:
Oracle 9.i


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 4:42 pm 
Newbie

Joined: Thu Dec 16, 2004 9:21 pm
Posts: 2
Location: San Jose, CA
Hi

SessionFactory configuration requires once when you startup your application. I'm sure you call only once. With Tomcat, you can put that config() in application scope.

I had the same problem--fist call's Ok, second call failed--. The way I fixed was every time after transaction tx.commit() or tx.rollback(), make sure that you call current seesion.close().

Here is the wrapper class for transaction control
...

private static SessionFactory sessionFactory = null;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();

....init()
{
...
sessionFactory =
new Configuration()
.addClass(***.class)
....... add more classes
..............
.setProperties(System.getProperties())
.buildSessionFactory();


public static void closeSession() {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {

s.close();
}
}
catch (HibernateException ex) {
new HibernateException(ex);
}
}

public static void beginTransaction() {
Transaction tx = (Transaction) threadTransaction.get();

try {
if (tx == null) {
tx = getSession().beginTransaction();
}
threadTransaction.set(tx);
}
catch (HibernateException ex) {
new HibernateException(ex);
}
}

public static void commitTransaction() {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
tx.commit();
}
threadTransaction.set(null);
}
catch (HibernateException ex) {
rollbackTransaction();
new HibernateException(ex);
}
}

public static void rollbackTransaction() {
Transaction tx = (Transaction) threadTransaction.get();

try {
threadTransaction.set(null);
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
tx.rollback();
}
}
catch (HibernateException ex) {
new HibernateException(ex);
}
finally {
closeSession();
}
}

}

Regards,

sithu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 4:56 pm 
Newbie

Joined: Mon Nov 22, 2004 1:04 pm
Posts: 5
Location: Denver, CO
I finally found it....

The issue has to do with which jar that is used for cglib. If I had
cglib-2.0.jar
it blew up every time.

Although, if I used the jar that was distributed with hibernate
cglib-full-2.0.2.jar
it works like a charm.

Hope this helps someone else.

Thanks,
Chad


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 8:24 am 
Newbie

Joined: Wed Jun 08, 2005 8:22 am
Posts: 2
Hi chadmuco

your hint did help me, thank you very much!

Andy


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.