I'm trying to do a test of the inheritance example in chapter 16.1 in the hibernate_reference.pdf. The example has an interface Payment with various subclasses. It uses the table-per-hierarchy mapping.
I'm trying to get the same result using XDoclet and the following test classes...
Interface IDog - XDoclet -
Code:
@hibernate.class table="Dog"
@hibernate.discriminator column="subclass" type="character"
@hibernate.id generator-class="native" type="int" column="Dog_ID" unsaved-value="0"
@hibernate.property column="Name" type="string" length="50" not-null="true" unique="false"
Class Poodle implements IDog - XDoclet -
Code:
@hibernate.subclass discriminator-value="P"
Class Boxer implements IDog - XDoclet -
Code:
@hibernate.subclass discriminator-value="B"
The XML that is generated from the XDoclet....
Code:
<class
name="com.matrix.bo.IDog"
table="Dog"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="Dog_ID"
type="int"
unsaved-value="0"
>
<generator class="native">
</generator>
</id>
<discriminator
column="subclass"
type="character"
/>
<property
name="name"
type="string"
update="true"
insert="true"
column="Name"
length="50"
not-null="true"
unique="false"
/>
</class>
Notice that is is missing the <subclass> tags.
Question 1.) Is there something wrong with my XDoclet? Does XDoclet not support this feature?Since this didn't look correct, I went ahead and manually added the needed <subclass> tags to the IDog.hbm.xml file.
Code:
<subclass
name="com.matrix.bo.Poodle"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="P"
>
</subclass>
<subclass
name="com.matrix.bo.Boxer"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="B"
>
</subclass>
When I tried a simple test to insert a Poodle and a Boxer....
Code:
session = sf.openSession();
tx = session.beginTransaction();
IDog poodle = new Poodle();
poodle.setColor("white");
poodle.setName("Fluffy");
IDog boxer = new Boxer();
boxer.setColor("brown");
boxer.setName("Rocco");
tx.commit();
...I got the following error.
MappingException Could not format discriminator value to SQL string
Question 2.) What does this error message mean? My xml looks like the example in chapter 16.1, I don't see what I'm missing.
Thanks in advance for any help!