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.  [ 4 posts ] 
Author Message
 Post subject: Can recursive classes be defined
PostPosted: Sun Apr 09, 2006 1:39 am 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
Hibernate version:
3.1

Name and version of the database you are using:
MySQL -- Innodb



I've been trying to create a somewhat compicated class but so far I am unsuccessful.

For simplicity, I will describe it thus:

Class A has a bunch of property items and a list which references class B. Class B has a bunch of property items and subclasses. Some of the subclasses have a list of B referenced (thus self referencial or recursive). With some twiddling I was able to get hibernate to not complain but at run time it stopped indicating that a foreign key condition had failed. I interpreted this as meaning that the list in the subclasses was being created before the list item in B.

My questionis whether this is possible at all. If not, what solutions may exist.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 2:05 am 
Beginner
Beginner

Joined: Mon May 09, 2005 5:26 pm
Posts: 21
Hello,

You seem to be asking two questions wrapped up in one. 1) How to do inheritance, and 2) how to do self-referential many-to-many mappings. I think your class A doesn't matter to the discussion.

For discussions on the various ways to handle inheritance, see primarily:
http://www.hibernate.org/hib_docs/v3/reference/en/html/inheritance.html (or, I suppose "primarily" should be The Book (Hibernate In Action)).

For the self-referential bit, nothing could be simpler. see: http://forum.hibernate.org/viewtopic.php?t=942169

You'll have to muck about a bit from those, but without more details on how you're doing inheritance, that's about all I can offer for now.

good luck,

-don.


Top
 Profile  
 
 Post subject: Can recursive classes be defined
PostPosted: Mon Apr 10, 2006 12:01 pm 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
I tried the hibernate definition referenced in http://forum.hibernate.org/viewtopic.php?t=942169 . I had some success but not complete success. I was able to generate a recursive definition, but for my application I needed a list, not a set. Items in the list were created as I expected but the index column never changed value for the entries. I would have expected there to be a different index value for each entry, starting from 0 for each (sub)list. All values are 0.

The referenced hibernate code is a set (http://forum.hibernate.org/viewtopic.php?t=942169) and mine is a list. Is there a different definition needed for a list than a set.

----

Here is the posted definition:

Code:
<class name="Person" table="person" lazy="true">
        <id name="id" column="id" type="java.lang.Long">
            <generator class="hilo"/>
        </id>       
   <set name="friends" table="person_friends" lazy="true" inverse="true">
         <key column="parent_id"/>
      <many-to-many class="Person" column="child_id"/>
   </set>       
</class>


and here is mine:

Code:
<class name="XXXStep" lazy="true">
        <id name="stepID">
            <generator class="native" />
        </id>
        <discriminator/>
        <property name="stepchildID" type="integer" />
        <property name="Type" not-null="true" />
        <property name="NText" type="text" not-null="false"></property>
        <property name="OffsetOption" not-null="false" />
        <property name="ScheduleTimeOffset" type="timestamp" not-null="false" />
        <property name="InclusionCondition" not-null="false" />
        <property name="StepTag" not-null="false" />
        <property name="Comment" type="text" not-null="false" />
        <property name="listIndex" type="integer"></property>
        <list name="otherXXX" cascade="all">
            <key column="stepID"></key>
            <index column="listIndex"></index>
            <many-to-many class="XXXStep" column="stepchildID" />
        </list>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 2:13 pm 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
Follow-up:

Hibernate also created an orderXXX table which holds the id's and the indices. When doing a load on the object, the lists appear. Too bad I can't keep everything in one table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.