Hi all,
I am finding it difficult to map two different classes (ClassA and ClassB) to different columns in the same table. Both classes share the same composite id, as shown below.
Code:
public class CompositeId {
public long compositeLong;
public String compositeString;
}
public abstract class BaseClass {
public CompositeId id;
}
public abstract class ClassA extends BaseClass {
public String propertyA;
}
public class ClassABlack extends ClassA {
public String propertyAtype1;
}
public class ClassAWhite extends ClassA {
public String propertyAtype2;
}
public abstract class ClassB extends BaseClass {
public String propertyB;
}
public class ClassBBlack extends ClassB {
public String propertyBtype1;
}
public class ClassBWhite extends ClassB {
public String propertyBtype2;
}
Table structure:
Code:
CREATE TABLE base_class (
composite_long int NOT NULL,
composite_string char(8) NOT NULL,
a_isblack char(1) NULL,
a_type1 char(8) NULL,
a_type2 char(8) NULL,
b_isblack char(1) NULL,
b_type1 char(8) NULL,
b_type2 char(8) NULL,
) ...
These two abstract classes, in turn, have to subclasses each, with a different discriminator column. It is possible to create and save an instance for any of the classes (say ClassAWhite). However, when creating and instance of any of the subclasses of ClassB, the discriminator column for this is not set correctly, being left as null. As an example, when trying to save an instance of ClassBBlack, the following SQL is generated:
Code:
update base_class set b_type1=? where composite_long=? and composite_string=?
This should be:
Code:
update base_class set b_isblack=?, b_type1=? where composite_long=? and composite_string=?
Any hints?
Hibernate version: 3.2.1
Mapping documents:Code:
<hibernate-mapping>
<class name="ClassA" table="base_class" abstract="true">
<composite-id name="id" class="CompositeId">
<key-property name="compositeLong" column="composite_long" type="long" />
<key-property name="compositeString" column="composite_string" />
</composite-id>
<discriminator column="a_isblack" not-null="true" type="string" />
<subclass name="ClassABlack" discriminator-value="Y">
<property name="propertyAtype1" column="a_type1" />
</subclass>
<subclass name="ClassAWhite" discriminator-value="N">
<property name="propertyAtype2" column="a_type2" />
</subclass>
</class>
<class name="ClassB" table="base_class" abstract="true">
<composite-id name="id" class="CompositeId">
<key-property name="compositeLong" column="composite_long" type="long" />
<key-property name="compositeString" column="composite_string" />
</composite-id>
<discriminator column="b_isblack" not-null="true" type="string" />
<subclass name="ClassBBlack" discriminator-value="Y">
<property name="propertyBtype1" column="b_type1" />
</subclass>
<subclass name="ClassBWhite" discriminator-value="N">
<property name="propertyBtype2" column="b_type2" />
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): N/A
Full stack trace of any exception that occurs: N/A
Name and version of the database you are using: Oracle 9.