-->
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: parent/child relation on same class, with list-index
PostPosted: Mon Apr 26, 2010 6:21 am 
Newbie

Joined: Mon Apr 26, 2010 5:33 am
Posts: 4
Hello, I am new to Hibernate and trying to map a parent-child relationship with list-index, where parent and child are the same class. I have a table with nodes and one with relations between nodes (childid, parentid, entryposition). Nodes can have more than one parent.

I tried the following mapping:

Code:
     <list name="children" table="RELATION" lazy="true" cascade="persist,merge,save-update" batch-size="20">
          <key column="PARENTID" not-null="true" update="false"></key>
          <list-index base="1">
             <column name="ENTRYPOSITION" precision="22" scale="0" />
          </list-index>
          <many-to-many column="CHILDID" class="KNOTEN"></many-to-many>
      </list>

        <set name="parents" inverse="true" lazy="true" table="RELATION" fetch="select" cascade="persist,merge,save-update" >
            <key update="false" >
                <column name="CHILDID" precision="22" scale="0" not-null="true" />
            </key>
            <many-to-many column="PARENTID" class="KNOTEN" />
        </set>


It is working when I insert a new child, but when I try to delete a child or reorder the children I get the following exceptions:

Could not execute JDBC batch update...
ORA-00001: Unique Constraint (...RELATION_PK) verletzt

What am I doing wrong?


Top
 Profile  
 
 Post subject: Re: parent/child relation on same class, with list-index
PostPosted: Mon Apr 26, 2010 6:28 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
not-null="false" update="true"


Top
 Profile  
 
 Post subject: Re: parent/child relation on same class, with list-index
PostPosted: Mon Apr 26, 2010 6:42 am 
Newbie

Joined: Mon Apr 26, 2010 5:33 am
Posts: 4
I think the problem is that childid and parentid are used as unique primarykey in the db and can not be set to null.
Maybe I should try to map the relation-table to an own class. I am not allowed to change the db-schema.
Any idea what would be the best way to handle this?


Top
 Profile  
 
 Post subject: Re: parent/child relation on same class, with list-index
PostPosted: Tue Apr 27, 2010 6:49 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
<set name="parents" inverse="true" lazy="true" table="RELATION" fetch="select" cascade="persist,merge,save-update" >
<key update="false" >
<column name="CHILDID" precision="22" scale="0" not-null="true" />
</key>
<many-to-many column="PARENTID" class="KNOTEN" />
</set>
?? whats this doing. why do you need this.Can a child have multiple parents??


Top
 Profile  
 
 Post subject: Re: parent/child relation on same class, with list-index
PostPosted: Tue Apr 27, 2010 6:56 am 
Newbie

Joined: Mon Apr 26, 2010 5:33 am
Posts: 4
yes, a child can have multiple parents and the entryposition depends on the parent


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