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.  [ 1 post ] 
Author Message
 Post subject: Covariant return types and UserType
PostPosted: Mon Jun 25, 2007 10:12 am 
Newbie

Joined: Fri Nov 03, 2006 5:21 am
Posts: 14
[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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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