-->
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: Undescriptive MappingException concerning extends
PostPosted: Thu Nov 02, 2006 11:02 am 
Beginner
Beginner

Joined: Thu Nov 02, 2006 9:38 am
Posts: 32
Location: Belgium
I'm using Hibernate 3.2.0 and HSQLDB. I have a lot (>50) of classes that need persisting, and there is quite some inheritance involved. The classes reside in many different packages, and I think that the packages are part of the problem.

The exception trace I get on when Hibernate loads its configuration is the following:

Quote:
org.hibernate.MappingException: Following superclasses referenced in extends not found: null,null,null,null (trimmed a bunch of nulls)
at org.hibernate.cfg.Configuration.processExtendsQueue(Configuration.java:1127)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1046)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)
at paragon.data.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:16)


When I add the package="my.pack.path" attribute for each mapping file to the hibernate-mapping tag, the various nulls in the error descriptors are prefixed with various package paths like null[my.pack.path]. Each mapping file corresponds to exactly one class. I have mapping files for my abstract classes (with abstract="true") and for my leaf classes. I tried with both union-subclass and join-subclass, it has no effect on the error. I use fully qualified names when referring to classes.

Here's a trimmed example of a mapping file for an abstract class:
Quote:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="paragon.data.universe.government">
<joined-subclass abstract="true" extends="paragon.data.universe.government.Government" name="paragon.data.universe.government.ParliamentaryGovernment" table="ParliamentaryGovernment">
<key column="id_"/>
<many-to-one class="paragon.data.universe.government.legislative.Parliament" name="parliament_"/>
</joined-subclass>
</hibernate-mapping>


And for a concrete class:

Quote:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="paragon.data.universe.government">
<joined-subclass extends="paragon.data.universe.government.ParliamentaryGovernment" name="paragon.data.universe.government.Nation" table="Nation">
<key column="id_"/>
<many-to-one class="paragon.data.universe.economy.Currency" name="currency_"/>
</joined-subclass>
</hibernate-mapping>


I've googled for this exception, but all I find are references to the source code of the Configuration class. I've examined the source code but couldn't get any wiser. Just to be sure, I've ordered my mapping files in my configuration file so that superclasses always precede subclasses.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 11:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
submit a runnable testcase to jira

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 5:24 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 9:38 am
Posts: 32
Location: Belgium
I looked into the problem myself, and it appears the null originate from org.hibernate.cfg.HbmBinder, on line 2984 (in my version of the source):

final String extendsName = element.attributeValue( "extends" );

It is not checked here that the document contains an extends attribute. Ignoring that possibility will lead to nulls leaking into the metamodel and later propagating themselves into errors.

I suggest placing checks for such possibilities, such as

if (extendsName == null)
{
throw new MappingException("Extends attribute should be defined for subclass, joined-subclass or union-subclass elements.");
}

This class of problems can be prevented by applying "Design by Contract": the extendsName variable is passed on later to another class' constructor, and if that constructor would have checked for null it would have been much easier to track down the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
still need a failing test to verify it actually fixes it.

would be great if you could supply that + the suggested patch to our jira

_________________
Max
Don't forget to rate


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.