-->
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.  [ 12 posts ] 
Author Message
 Post subject: NoClassDefFoundError with null message is a rubbish error
PostPosted: Fri Jun 04, 2004 6:01 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
I have 2 classes A and B. B is subclass of A. A contain an ID and B contains a name. So the mapping file is quite simple. I get the error below. Any clues? Thanks for any help.

hib version: 2.1.3
database: m$ sql server 2000

mapping file...
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="org.tireetoo.tig.core.A"
table="A"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-A.xml
containing the additional properties and place it in your merge dir.
-->

<joined-subclass
name="org.tireetoo.tig.core.B"
table="B"
dynamic-update="false"
dynamic-insert="false"
>
<key
column="B_ID"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>

</joined-subclass>

</class>

</hibernate-mapping>

contents of log file...
2004-06-04 10:58:16,561 INFO cfg.Environment [main] Hibernate 2.1.3
2004-06-04 10:58:16,561 INFO cfg.Environment [main] hibernate.properties not found
2004-06-04 10:58:16,577 INFO cfg.Environment [main] using CGLIB reflection optimizer
2004-06-04 10:58:16,593 INFO cfg.Configuration [main] configuring from resource: /hibernate.cfg.xml
2004-06-04 10:58:16,593 INFO cfg.Configuration [main] Configuration resource: /hibernate.cfg.xml
2004-06-04 10:58:16,780 INFO cfg.Configuration [main] Mapping resource: org/tireetoo/tig/core/A.hbm.xml
2004-06-04 10:58:16,890 INFO cfg.Binder [main] Mapping class: org.tireetoo.tig.core.A -> A
2004-06-04 10:58:17,030 INFO cfg.Binder [main] Mapping joined-subclass: org.tireetoo.tig.core.B -> B
2004-06-04 10:58:17,030 INFO cfg.Configuration [main] Mapping resource: org/tireetoo/tig/core/B.hbm.xml
2004-06-04 10:58:17,030 ERROR testclient.ServiceTest [main] bad stuff - ex message: null
java.lang.NoClassDefFoundError
at org.tireetoo.tig.testclient.ServiceTest.testRolesAndUsers(ServiceTest.java:77)
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 junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:523)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:03 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
How should we know, we don't have ServiceTest.java:77

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:18 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
Line 77 is the HibernateUtil.closeSession()line.
HibernateUtil has the usual...
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}
Is this the problem?

Apologies for not including the test code...

package org.tireetoo.tig.testclient;

import junit.framework.TestCase;
import org.tireetoo.tig.service.CentralSystem;
import org.tireetoo.tig.api.*;
import org.tireetoo.tig.core.*;
import org.tireetoo.tig.persistence.HibernateUtil;
import org.picocontainer.PicoContainer;
import org.apache.log4j.Logger;

import java.util.Set;
import java.util.TreeSet;

import net.sf.hibernate.Transaction;
import net.sf.hibernate.Session;
import net.sf.hibernate.HibernateException;






/**
*
*
*/
public class ServiceTest extends TestCase {

private static Logger LOG = Logger.getLogger(ServiceTest.class.getName());

public ServiceTest(String s) {
super(s);
}

public void setUp() {
}

public void testRolesAndUsers() throws Throwable {
// get pico container
PicoContainer pc = CentralSystem.getInstance().getContainer();

Transaction tx = null;

try {
// start transaction here
Session sess = HibernateUtil.currentSession();
tx = sess.beginTransaction();

// create some roles
BService rs = (BService)pc.getComponentInstanceOfType(BService.class);
B adminRole = rs.createRole("system-administrator");
B respRole = rs.createRole("responsible-officer");

// and some users
Set defaultAdminRoles = new TreeSet();
defaultAdminRoles.add(adminRole);
CService us = (CService)pc.getComponentInstanceOfType(CService.class);
C user = us.createUser("bob", "bobby", defaultAdminRoles);

Set defaultRespOffRoles = new TreeSet();
defaultRespOffRoles.add(respRole);
C user2 = us.createUser("tom", "thomas", defaultRespOffRoles);

// and commit here
tx.commit();
} catch(Exception ex) {
if (tx != null) {
try {
tx.rollback();
} catch (HibernateException e) {
throw e;
}
}
} finally {
// make sure that the session is closed
try {
HibernateUtil.closeSession();
} catch (Throwable ex) {
LOG.error("bad stuff - ex message: " + ex.getMessage(), ex);
throw ex;
}
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:19 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
A bit more info.
This test is run from ANT 1.6.1 with a fork new JVM.
It is a JUnit test.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:20 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Replace this:

Code:
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}


with that:

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


Yes, I know that you got it from the Hibernate documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:26 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
In the log file I now get...
net.sf.hibernate.MappingException: Resource: org/tireetoo/tig/core/B.hbm.xml not found
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:331)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:990)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:946)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:860)
at org.tireetoo.tig.persistence.HibernateUtil.<clinit>(HibernateUtil.java:18)

Which is because I mention it in my hibernate.cfg.xml file but I dont create it because all the info is in A.hbm.xml !! Dah, Dah.

Its not easy getting all the info out of users is it. :-)
Thanks very much for the help.

If all my persistent types derive from a common type that includes an ID and a name, creation time etc. Is it okay for all the mapping info to go into one file?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:28 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
One mapping file per persistent class is common practice (and expected by some tools).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:33 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
How do I get hibernate to create one mapping file per persistent class?

However I am not getting any data saved now. No rows in tables.
Should I turn on hibernate debug logging and get back with results?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:42 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You should start reading the documentation and tutorials.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, and for inheritance mappings, you can either put the whole class hierarchy in a single mapping file (of course, since <subclass> and <joined-subclass> are child elements of <class>) or use the <class extends=""> mapping.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 6:49 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
Can I get xdoclet to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 7:09 am 
Beginner
Beginner

Joined: Thu Jan 15, 2004 11:16 am
Posts: 37
Well it all came down to the catch block in ServiceTest. It was catching exception, rolling back transaction and NOT throwing the transaction higher up the chain (and failing to log it). The anti-pattern of transaction swallowing.

Basically dodgy coding. :-)

Thanks for all the help christian.
I have to add that this is the fastest, best informed and helpful developer forum I have come across. Even better than NSIS. :-) And loads better than the TopLink support we used in the past.

You guys just need to get rid of that naff NoClassDefFoundError with null message. :-)

Im now back on the developing enterprise app track. And happy too.


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