-->
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.  [ 5 posts ] 
Author Message
 Post subject: Subclass w/ discriminator an One-to-many association problem
PostPosted: Thu Jul 12, 2007 3:46 pm 
Newbie

Joined: Thu Jul 12, 2007 3:10 pm
Posts: 2
Location: Virginia, USA
Hibernate Version: 3.2

I would like to extend Cat/Domestic Cat inheritance example from

http://www.hibernate.org/hib_docs/v3/reference/en/html_single/

and add a Cage where one or more Domestic Cats can stay together. So I am adding a Cage table with CageID in it and have it in DomesticCat table as foreign key.

While I am trying to load a Cage from Hibernate it is trying to join Cage with both Cat and DomesticCat and failing since cage ID exist only in DomesticCat table.

DomesticCat.hbm.xml contains:
Code:
<many-to-one name="cage" column="CageID" lazy="false" />


Cage.hbm.xml contains:

Code:
<subclass name="DomesticCat" extends="Cat" discriminator-value="DOM">
     <join table="DOMESTIC_CAT">
        <many-to-one name="cage" column="CageID" lazy="false" />
      </join>
</subclass>


Doe any one have idea how to resolve this issue?

_________________
Saleem Arif
IT Consultant


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 3:51 pm 
Newbie

Joined: Thu Jul 12, 2007 3:10 pm
Posts: 2
Location: Virginia, USA
Oops!

Here are correct code segments:

DomesticCat.hbm.xml contains:

Code:
<subclass name="DomesticCat" extends="Cat" discriminator-value="DOM">
     <join table="DOMESTIC_CAT">
        <many-to-one name="cage" column="CageID" lazy="false" />
      </join>
</subclass>


Cage.hbm.xml contains:

Code:
<bag name="domesticCats" lazy="false" inverse="true">
    <key column="cageID" not-null="true"/>
    <one-to-many class="DomesticCat"/>
</bag>

_________________
Saleem Arif
IT Consultant


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 9:56 pm 
Newbie

Joined: Sun Sep 09, 2007 9:26 pm
Posts: 8
Hello,

I push this topic up since it's unsolved and I'm getting exactly the same problem.

Also, when cascade="all-delete-orphan" is set in the bag definition, and when deleting a Cage, only rows from the "domesticCat" table are deleted, the corresponding rows in the "cat" table are left.

However, when deleting a specific DomesticCat, the corresponding Cat rows are also deleted.

Sounds like a bug ... or another hibernate trick !


Top
 Profile  
 
 Post subject: Same exact problem
PostPosted: Mon Feb 04, 2008 10:50 pm 
Newbie

Joined: Wed Aug 24, 2005 1:43 pm
Posts: 10
Hi,
We're experiencing the same problem with Hibernate 3.2.5
any solution identified for this problem?
Thanks,
Sebastien


Top
 Profile  
 
 Post subject: Problem with multi-level inheritence with parent child ref
PostPosted: Fri Feb 08, 2008 8:08 am 
Newbie

Joined: Fri Feb 08, 2008 6:53 am
Posts: 4
I'm getting a similar problem when mixing inheritence strategies of subclass and join (as described in the reference document). As I have a large class structure, and I want to avoid lengthy SQL select statements, I have chosen the discriminator strategy. I admit, I've never used it before, so, hopefully, this problem is down to my implementation.

The mapping below is for an entity that sub-classes AbstractOrgEntity using the discriminator method. The OrgUnit has a parent/child relation with entities of the same type, but this is reflected only in the table ORGUNIT and not the table of AbstractOrgEntity.

When I try and retrieve the sub-units of a given OrgUnit, the SQL generated incorrectly references a non-existent PARENT_ID column in the AbstractOrgEntity table.

The problem would seem to be that the <set> for subUnits is not within the <join> element, and so Hibernate assumes the property belongs to the AbstractOrgEntity table. Unfortunately, you can't place the <set> within the <join> as the XML schema disallows it - and I guess Hibernate would complain even if the schema didn't.

I don't think this is a bug as more of an oversight.

Does anyone have a work-around?

Code:
<hibernate-mapping>
  <subclass name="OrgUnit" extends="AbstractOrgEntity" discriminator-value="12">

    <!-- bi-directional one-to-many composite association to OrgUnitType -->
    <!-- this is the parent reference to its children -->
    <set name="subUnits" lazy="true" inverse="true" cascade="all-delete-orphan">
      <key column="PARENT_ID"/>
      <one-to-many class="OrgUnit"/>
    </set>

    <join table="ORGUNIT">
      <key column="id"/>

      <property name="description" column="DESCRIPTION" type="string"/>

      <!-- bi-directional many-to-one composite association to OrgUnitType -->
      <!-- this is the child reference to the parent -->
      <many-to-one name="parent" column="PARENT_ID"
                  class="OrgUnit" not-found="ignore" not-null="false"/>
    </join>
  </subclass>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.