Hibernate version:
2.1.2, tools 2.0.1 and 2.1.6, tools 2.1.2
Name and version of the database you are using:
Oracle 9i
I am trying to create a mapping that has a single base class, a subclass, and a sub-subclass, using the table-per-subclass mapping strategy. (I know this strategy is not recommended, but this is legacy data, so I have no other choice.)
Below is a quote from gavin in another post which says that I should be able to accomplish this:
Quote:
There is, of course, no limit to the depth of inheritance in Hibernate.
However, I encounter the problem that there is no way to map the sub-subclass without getting a MappingException at code-generation time. Say C inherits from B inherits from from A. When code generating C, I get the following error even if B generates successfully
Exception:
net.sf.hibernate.MappingException: Cannot extend unmapped class com.twcaustin.intranet.myforms.model.B
Mapping documents:
These mappings represent a simplest-case for the problem I have experienced in my project.
A.hbm.xml
Code:
<?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 package="com.twcaustin.intranet.myforms.model">
<class name="com.twcaustin.intranet.myforms.model.A" table="A">
<id
name="id"
type="java.lang.Long"
column="ID"
unsaved-value="null"
access="property">
<generator class="sequence">
<param name="sequence">seq_ID</param>
</generator>
</id>
<version name="name" type="string" column="name" unsaved-value="null" />
</class>
</hibernate-mapping>
B.hbm.xmlCode:
<?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 package="com.twcaustin.intranet.myforms.model">
<joined-subclass name="com.twcaustin.intranet.myforms.model.B"
extends="com.twcaustin.intranet.myforms.model.A"
table="B" >
<key column="ID" foreign-key="id" />
<property name="title" column="TITLE" type="string" />
</joined-subclass>
</hibernate-mapping>
C.hbm.xmlCode:
<?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 package="com.twcaustin.intranet.myforms.model">
<joined-subclass name="com.twcaustin.intranet.myforms.model.C"
extends="com.twcaustin.intranet.myforms.model.B"
table="C" >
<key column="ID" foreign-key="id" />
<property name="ln" column="LN" type="string" />
</joined-subclass>
</hibernate-mapping>
I am using an ANT task that looks like this, which I have been using successfully to generate other Hibernate classes for some time:
Code:
<java classname="net.sf.hibernate.tool.hbm2java.CodeGenerator" fork="true">
<classpath refid="hibernate.classpath" />
<classpath location="${hbmdata.jar}" />
<arg value="--output=${gensrc}" />
<arg line="${hbm.files}" />
</java>
Here is the complete stack trace for the error given by the generator:
Code:
[java] net.sf.hibernate.MappingException: Cannot extend unmapped class com.twcaustin.intranet.myforms.model.B
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:137)
[java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:109)
I have found this error in the JIRA and it says it was fixed 22/Jul/04 05:12 PM.
http://opensource.atlassian.com/projects/hibernate/browse/HB-1097
Once I found that, I upgraded from hibernate 2.1.2/tools 2.0.1 to hibernate 2.1.6/tools 2.1.2. This should have included the fix, but I still get the error.
Additionally, the JIRA bug says that the posted patch.txt does not actually fix the problem.
Additionally, I do not seem to be able to put the base class in one JAR file, and then import that JAR in my ant task to generate a the subclasses. I have not been able to find a JIRA bug listing for this problem.
Is there any known workaround for these issues, or is there a build that is known to have these fixes?
I am sorry if this is the wrong place to post this, but I feel like I have done due dilligence through all other sources. I am getting desperate, because I don't know how to finish my project without this capability and don't know where else to turn.
Thank you in advance for any assistance you can provide.
DW