-->
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: Polymorphism mapping issues (bug?)
PostPosted: Tue Mar 01, 2005 11:36 pm 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
Hibernate version: 3.0b4

Following is an excerpt of a mapping document which has the problem
Mapping documents:
Code:
    <class name="NetworkObject" abstract="true">
        <id name="id"
            type="int"
            column="ID"
            unsaved-value="-1">
            <generator class="native"/>
        </id>

        <discriminator column="OBJ_TYPE" type="string"/>

        <version name="version"
                 type="int"
                 column="VERSION"/>

        <!-- Common name property. -->
        <property name="name"
                  type="string"
                  column="NAME"
                  length="100"
                  update="false"/>

     < ... other properties ommited ... >


        <!--
            define base hierarchy classes.

            Note the referenced classes are synthetic classes only used to support
            the Hibernate inheritance mechanism which only allows union-subclass to
            exist as a child element of class and cannot exist as a child of hibernate-mapping.

            Each concrete hierarchy root defines a private version of the 'Base' class to satisfy Hibernate
        -->
        <union-subclass name="BaseNE" abstract="true" table="NE" />
        <union-subclass name="BasePort" abstract="true" table="PORT"/>
table="ROUTE"/>-->

    <subclass name="NE" extends="BaseNE">
    <....>
    </subclass>

    <!-- Port Hierarchy (mapped into its own table, specified in BasePort -->
    <subclass name="Port" extends="BasePort">
        <property name="slot" type="int" column="SHELF_SLOT"/>
        <property name="index" type="int" column="PORT_INDEX"/>
       
        <many-to-one name="ne"
            class="NE"
            column="NE_ID" />

         < ... >
    </subclass>

    <subclass name="ATMPort" extends="Port" discriminator-value="A"/>
    <subclass name="GEPort" extends="Port" discriminator-value="G"/>



The intention is to have all classes derived from NetworkObject reside in
several tables, one per sub-hierarchy, whilst still having all the properties
defined in NetworkObject above. Secondly there's a couple of other classes, not mentioned here, which have references to NetworkObject type objects (collections thereof).

This mapping code is compiled/parsed successfully by the SchemaExport
tool and generates a ddl fragment. The problem stems from the fact
that the generated tables do not have a primary key constraint generated
for them and so, generated foreign keys like the NE_ID in the Port subclass above cannot be created since the NE table does not have the ID column (as inherited
from NetworkObject) as primary key.

Can I use this technique at all to achieve what I want?

Looking at the code, Port and NE are both instances of DenormalizedTable
and it seems that it does not use the idValue property of the included
table. Is this a bug?

_________________
Cheers,

Bonny

please don't forget to rate :)


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.