-->
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.  [ 2 posts ] 
Author Message
 Post subject: Subclass referencing other subclass of superclass problem
PostPosted: Thu Mar 11, 2004 4:47 am 
Newbie

Joined: Thu Oct 09, 2003 4:30 am
Posts: 7
I'm using Hibernate 2.0.1 with McKoi 1.0

I have problems with a one-to-many reference of a subclass referencing another subclass of
the same superclass.

The following mapping define a class called BaseItem. It has two subclasses that extends
the functionality of BaseItem. The ArrayItem subclass contains a one-to-many association
with the Item subclass.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
  <class name="dvs.summit.data.items.BaseItem" table="Item" discriminator-value="base">
    <id name="id" type="long" column="id" unsaved-value="null">
      <generator class="hilo"/>
    </id>
    <discriminator column="type"/>
    <many-to-one name="device" column="device_id" class="dvs.summit.devices.DeviceData"/>
    <property name="itemIndex" column="itemIndex" type="integer"/>
   
    <!-- Item subclass -->
    <subclass name="dvs.summit.data.items.Item" discriminator-value="item">
      <property name="arrayIndex" column="arrayIndex" type="integer"/>
      <property name="valueId"  column="value_id"/>
      <many-to-one name="owningArray" column="arrayItem_id"/>
      <subclass name="dvs.summit.data.items.StringItem" discriminator-value="string"/>
      <subclass name="dvs.summit.data.items.BCDItem" discriminator-value="bcd"/>
      <subclass name="dvs.summit.data.items.IntegerItem" discriminator-value="integer">
        <subclass name="dvs.summit.data.items.S8Item" discriminator-value="S8"/>
        <subclass name="dvs.summit.data.items.S16Item" discriminator-value="S16"/>
        <subclass name="dvs.summit.data.items.S32Item" discriminator-value="S32"/>
        <subclass name="dvs.summit.data.items.S64Item" discriminator-value="S64"/>
        <subclass name="dvs.summit.data.items.U8Item" discriminator-value="U8"/>
        <subclass name="dvs.summit.data.items.U16Item" discriminator-value="U16"/>
        <subclass name="dvs.summit.data.items.U32Item" discriminator-value="U32"/>
      </subclass>
      <subclass name="dvs.summit.data.items.FloatItem" discriminator-value="float">
        <subclass name="dvs.summit.data.items.F32Item" discriminator-value="F32"/>
        <subclass name="dvs.summit.data.items.F64Item" discriminator-value="F64"/>
        <subclass name="dvs.summit.data.items.FloatDecItem" discriminator-value="FD64"/>
      </subclass>
      <subclass name="dvs.summit.data.items.DateItem" discriminator-value="date">
        <subclass name="dvs.summit.data.items.D32Item" discriminator-value="D32"/>
        <subclass name="dvs.summit.data.items.D64Item" discriminator-value="D64"/>
      </subclass>
      <subclass name="dvs.summit.data.items.ByteArrayItem" discriminator-value="binary"/>
      <subclass name="dvs.summit.data.items.AlarmItem" discriminator-value="alarm"/>
    </subclass>
   
    <!-- Array subclass -->
    <subclass name="dvs.summit.data.items.ArrayItem" discriminator-value="array">
      <list name="items" inverse="true" cascade="all">
        <key column="arrayItem_id"/>
        <index column="arrayIndex"/>
        <one-to-many class="dvs.summit.data.items.Item"/>
      </list>
      <subclass name="dvs.summit.data.items.StringArrayItem" discriminator-value="string-array"/>
      <subclass name="dvs.summit.data.items.AlarmArrayItem" discriminator-value="alarm-array"/>
    </subclass>
  </class>
</hibernate-mapping>

The problem is that the referenced Items (referenced by ArrayItem) has always null values
for its BaseItem properties device_id and itemIndex.

Code:
id    type    device_id    itemIndex    arrayIndex    arrayItem_id
-----------------------------------------------------------------------------
100    array    5            7         null          null
101    S8      null        null        0              100
101    S8      null        null        1              100
101    S8      null        null        2              100

it should be (I think)
Code:
id    type    device_id    itemIndex    arrayIndex    arrayItem_id
-----------------------------------------------------------------------------
100    array   5            7            null          null
101    S8      5            7            0              100
101    S8      5            7            1              100
101    S8      5            7            2              100

It seems that Hibernate never calls getDevice() and getItemIndex() for the items
referenced by the ArrayItem.

Can someone please tell me what's wrong?


Top
 Profile  
 
 Post subject: Fixed by downloading McKoi 1.0.2
PostPosted: Thu Mar 11, 2004 10:27 am 
Newbie

Joined: Thu Oct 09, 2003 4:30 am
Posts: 7
McKoi bug.


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

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.