[b]Hibernate version: 3.2.4
Hi folks,
I have the following inheritance situation that I want to solve with Hibernate:
Code:
-----------------
| BaseEntity |
-----------------
| oid : BaseOID |
| .... |
-----------------
^
/ \
-----
|
|
|
---------------------
| EntityB |
---------------------
| oid : EntityB_OID |
| .... |
---------------------
EntityB extends BaseEntity and EntityB_OID extends BaseOID.
BaseOID and all inherited OIDs are mapped as CompositeUserTypes where each OID has a long value as Id and potentially other attributes.
Each entity has a method getOID() that is defined in the BaseEntity and BaseOID provides a method "long getId()". The subclass overrides the getOID() method and return a sub-class from BaseOID (covariant return type).
I want to use the table-per-hierarchy mapping strategy and create a mapping like this:
Code:
<hibernate-mapping>
<class name="EntityA">
<discriminator column="I_SUBCLASS" type="string" length="64"/>
<property name="oid" type="OIDUserType">
<column name="A_LONG"/>
</property>
<subclass name="EntityB"discriminator-value="entityB">
<!-- override the superclass property so that the correct sub-type of the OID is generated -->
<property name="oid" type="EntityBOIDUserType">
<column name="A_LONG"/>
<column name="ANOTHER"/>
</property>
</subclass>
</class>
</hibernate-mapping>
Basically I want to define the ID column in the base class and use a different UserType in each subclass so that each subclass can return a subclass of the BaseOID class (covariant return type).
Is there any possibility to do that?
The above solution doesn't work, because it throws a
org.hibernate.MappingException: Repeated column in mapping for entity: EntityB column: A_TYPE (should be mapped with insert="false" update="false")
Thanks in advance,
joijoe