-->
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.  [ 14 posts ] 
Author Message
 Post subject: Problem with Standalone app in a non-managed environment
PostPosted: Wed Nov 23, 2005 12:49 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
I have an application which is implemented in two ways: one implementation uses a web front end (html, servlets, tomcat, etc), and the other uses a swing front end with no app server or servlet engine of any kind.

The web front-end implementation works like a champ! (I did it first.) I am having problems making the swing standalone implementation work. I obviously had to modify the configuration some (no tomcat, no jndi, no tomcat connection pool, etc). I have solved many problems of configuration to get to this point, but now I believe I have a complete and sound configuration (maybe not) but the application craters with an exception I can't sort out when the code executes the HibernateUtil. As best I can tell it never returns from trying to build the session factory.

Here is the exception report I get:

Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@6545d2 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1dd9891 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 20, maxIdleTime -> 300, maxPoolSize -> 100, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 20, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@c0c8b5 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost:3306/CSRapp, properties -> {user=******, password=******} ] , preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] , factoryClassLocation -> null, numHelperThreads -> 3, poolOwnerIdentityToken -> 6545d2 ]
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError
at org.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:321)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at suncertify.db.HibernateUtil.<clinit>(Unknown Source)
at suncertify.db.ModelFacade.findAllLikeThis(Unknown Source)
at suncertify.client.gui.SelectionPage.findAllLikeThis(Unknown Source)
at suncertify.client.gui.SelectionPage.doSearch(Unknown Source)
at suncertify.client.gui.SelectionPage.access$000(Unknown Source)
at suncertify.client.gui.SelectionPage$4.actionPerformed(Unknown Source) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)

The first part is the report back from a (successful, I think) startup of the c3p0 connection pooling facility. I include it because it shows many configuration parameters. Then there is this exception ... a NoClassDefFoundError, but I cannot identify what class it can't find ... and it looks to me that it is deep in the hibernate code when it craters. Notice that it does not report an Initializer error. I looked at line 321 in the source for SessionFactoryImpl but that didn't really tell me anything I could use.

My hibernate.cfg.xml follows:

<hibernate-configuration>

<session-factory>

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/CSRapp </property>
<property name="connection.username">CSRapp</property>
<property name="connection.password">XXXX</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="c3p0.min_size">20</property>
<property name="c3p0.max_size">100</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">3000</property>
<property name="show.sql">false</property>

<!-- Mapping files -->
<mapping resource="suncertify/client/ServiceProvider.hbm.xml"/>

</session-factory>

</hibernate-configuration>

I will certainly be grateful for any guidance any of you might like to offer. I have beat my head against this brick wall longer than a fella should ever have to do.

Frankly, I believe the problem is related to the fact that it is running in a non-managed environment. The symptoms suggest to me this is either an internal hibernate problem (dare I say bug?) or it certainly could be some configuration issue I have overlooked (but all the configuration issues seem to have executed successfully) ... or... lord knows what else it might be.

Remember, both implementations use exactly the same classes at the back end. The successful web implementation runs through the very same code as does this implementation which does not succeed. I am surely puzzled!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 1:46 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Its complaining about a ClassNotFound and the line number indicates a
net.sf.cglib.core.KeyFactory. Are you sure you have the cglib-full.jar included in ur classpath where this class is defined.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 9:55 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
Well, I will check that today. Thanks for the steer. I will report results later.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 10:00 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
I was able to check that right away.

I have cglib-2.1.jar in path, as used by the web front-ended app. That is the only cglib included in the hibernate distribution. Is there another called, "cglib-full_something"?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 5:15 pm 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
I do hope someone will chime in on this. I just don't know what to do next. I will appreciate any suggestion on how to fix, how to diagnose, or wire around this problem.

The best way to make me go away is to help me get this bugger fixed !!
;)

Thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 5:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Dude, its the first FAQ on the website.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 12:38 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
Oh, my! I am embarrassed. I really should have seen that in the FAQ. That was a useful stear. And I count myself properly chastised for not seeing it earlier... However, Dude, ... it has not solved my problem. I have thrown about everything in the hibernate/lib directory into classpath for this app. Nothing so far has helped.

Soooo .... I stepped back ... re-looked at the exception report:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError
at org.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:321)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)

I looked again at the source code for SessionFactoryImpl ... looked at line 321. I believe rajasaur had the right idea ... almost. Here is the code around that line number:

//returns generated class instance
private static final QueryCacheKeyFactory QUERY_KEY_FACTORY;
private static final FilterCacheKeyFactory FILTER_KEY_FACTORY;
static {
QUERY_KEY_FACTORY = (QueryCacheKeyFactory) KeyFactory.create(QueryCacheKeyFactory.class);
FILTER_KEY_FACTORY = (FilterCacheKeyFactory) KeyFactory.create(FilterCacheKeyFactory.class); <-- line 321
}

static interface QueryCacheKeyFactory {
//Will not recalculate hashKey for constant queries
Object newInstance(String query, boolean scalar);
}

static interface FilterCacheKeyFactory {
//Will not recalculate hashKey for constant queries
Object newInstance(String role, String query, boolean scalar);
}

KeyFactory, is indeed a class from the cglib jar. I have confirmed that jar is in classpath and the application is accessing that jar oaky. The other class the code is accessing in that line of code is the "FilterCacheKeyFactory.class" ... but that is an inner class within SessionFactoryImpl itself. That class exists in hibernate3.jar ... and I have confirmed that jar is within classpath and the app is accessing that jar, also. The exception report does indicate the problem is occurring during class initialization time, during the static block execution time of SessionFactoryImpl. I set the logger priority to "debug" and checked that, but it did not provide any additional useful information. I am using Java 1.5. I have tried recompiling everything in the app with Jdk 1.4.2 ... (maybe the classloaders are somehow different) ... that made no difference.

What I need to know is exactly what class is it that was not found, then maybe I will be able to ensure that class is available to the app.

Here I am ... still puzzled.

By the way, I did re-confirm ... the application does still run okay if using the web frontend ... and tomcat.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 2:41 am 
Beginner
Beginner

Joined: Sun Oct 16, 2005 3:07 am
Posts: 33
Location: Sydney
Just a thought...

How are you starting the swing app. If executable Jar, have you got the manifest file set up properly to point to all the other jars you need?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 10:30 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
Thanks, Craig, for this useful suggestion.

When I get it to work it _will_ be run as an executable jar, and I will have to edit the manifest to include all the jars. However, during development I start it by running a script. This is the startup script:

java -cp .:app:docs/CSsysHelp/lib/jhbasic.jar:docs/CSsysHelp:app/lib/hibernate3.jar:app/lib/mysql-connector-java-3.1.10-bin.jar:app/lib/antlr-2.7.5H3.jar:app/lib/asm-attrs.jar:app/lib/cglib-2.1.jar:app/lib/commons-collections-2.1.1.jar:app/lib/commons-logging-1.0.4.jar:app/lib/dom4j-1.6.jar:app/lib/ehcache-1.1.jar:app/lib/log4j-1.2.9.jar:app/lib/jta.jar:app/lib/c3p0-0.8.5.2.jar CSsys

#
# app/lib/jdbc2_0-stdext.jar:app/lib/connector.jar:app/lib/jaas.jar:app/lib/xml-apis.jar:app/lib/jacc-1_0-fr.jar

It doesn't display well here; the long lines in this display start on tha next line. Actually, in the script, they are on the same line as the characters showing on the previous line here. The list of commented out jars are jars I added - one by one - to the classpath, but none of those had any effect on my problems. There is one jar where the instructions do specify I will need it in a standalone application (jdbc2_0-stdext.jar) . I will put it back in when I findI need it.

Thanks for offering suggestions. Right now I am in the process of adding every frigging jar mentioned in hibernate/lib/_README.txt - one at a time - to the classpath. However, the exception report does not seem to me to indicate any of this effort will solve this problem. I need somehow to discover the name of the class it can't find.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 6:47 pm 
Beginner
Beginner

Joined: Sun Oct 16, 2005 3:07 am
Posts: 33
Location: Sydney
Post your HibernateUtil code if thats where you think it is falling over. Is your mapping file on the classpath?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 12:27 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
Thanks for hanging in with me, Craig.

Here is the HibernateUtil.java:

package suncertify.db;

import org.hibernate.*;
import org.hibernate.cfg.*;
import org.apache.commons.logging.*;

public class HibernateUtil {

private static Log log = LogFactory.getLog(HibernateUtil.class);

private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Exception ex) {
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal session = new ThreadLocal();

public static Session getSession() {
Session s = (Session) session.get();
// Open a new session, if this thread has none yet.
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() {
Session s = (Session) session.get();
if (s != null) s.close();
session.set(null);
}

} // End class HibernateUtil

Pretty much straight out of the manual. See the first line in the static initializer; the code is not coming back from the buildSessionFactory call. But also note the code does not throw an ExceptionInInitializerError.

Now, your point about the mapping file and its accessability is a very good point! I did not have it explicitly in path, but I think hibernate should be able to find it from the hibernate.cfg.xml file, which is in path. I tried putting the directory where the mapping file (there is only one in this app) resides explicitly in classpath but that made no difference. Still, I want to confirm that hibernate sees that file okay. I may turn the logger to debug again to see if I can get confirmation of that. Good idea, Craig. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 12:33 am 
Beginner
Beginner

Joined: Sun Oct 16, 2005 3:07 am
Posts: 33
Location: Sydney
Try catching Throwable instead of Exception. I think that's why it's not coming back after the buildSessionFactory() call. NoClassDefFoundError is a subclass of Throwable, not Exception


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 12:51 am 
Beginner
Beginner

Joined: Sun Oct 16, 2005 3:07 am
Posts: 33
Location: Sydney
I should say, a subclass of Error, not Exception. Let me know how you get on but I think you'll find the class that is missing when you catch Throwable


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 1:41 am 
Beginner
Beginner

Joined: Sun Sep 25, 2005 11:57 am
Posts: 29
Wow! Isn't it always the stupid mistakes that kill us!!

I have found it. Craig, your counsel about the mapping file caused me to set up so I could chase that issue ... running the logger in debug mode and studying the output, I saw a note that the reflection optimiser was turned off because the system could not find the class: org/objectweb/asm/Type Well, I chased into the jar files I have in the application lib directory and - Lo! - I found it in asm.jar Why that is one of the jars I already have in classpath, right? Uh, well, I thought it was in classpath ... but it wasn't!! It was in the lib directory but I had failed to include it in the classpath statement. Dumb! Dumb!! Silly oversight!!!

Well, so now everything works okay. Frustrating and depressing to have lost so much time for so simple an error on my part ... but, at least it now works.

Craig, I owe ya' for hangin' in with me and helping me chase after this problem. Thank you.

Thank you all who contributed to my search.


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