-->
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: inverse="true" when parent/child are the same object.
PostPosted: Tue Oct 19, 2010 12:52 pm 
Newbie

Joined: Tue Oct 19, 2010 12:26 pm
Posts: 2
I have an application that uses a Hierarchy of objects in a parent-child structure. I am trying to improve the performance of a cascaded delete which is currently very slow. I think I can do this if I set inverse="true" on the one-to-many side of the relationship, but when I do the relationship breaks and my parentId and idx fields are always set to null in mysql.

This is how the relationship is set up:

Code:
<class name="MyObject" table="MyTable">
   <id name="id" column="id" type="java.lang.Long">
      <generator class="increment"/>
   </id>
            
   <property name="parentId" />
   <property name="name" />

   <many-to-one name="parent"
      column="parentId" insert="false" update="false"/>

   <list name="col" inverse="true" cascade="all-delete-orphan">
      <key column="parentId"/>
      <index column="colIdx"/>
      <one-to-many class="MyObject"/>
   </list>
</class>


And I am adding objects like this:
Code:
MyObject parent = new MyObject();
parent.setName("Parent");
transaction = session.beginTransaction();
session.save(parent);
transaction.commit();

...

MyObject child = new MyObject();
child.setName("Child");
transaction = session.beginTransaction();
parent.addChild(child);
transaction.commit();


The instructions I am following indicate that I should do this:

Code:
<key column="parentId" not-null="true"/>


However I can't because my root object does not have a parent.

I've been trying different things all day and I'm stuck. It works fine without inverse="true".


Top
 Profile  
 
 Post subject: Re: inverse="true" when parent/child are the same object.
PostPosted: Mon Oct 25, 2010 7:32 am 
Newbie

Joined: Tue Oct 19, 2010 12:26 pm
Posts: 2
A little progress, I found that I was not using setParent() when adding a child to a parent which fixed the NULL value for the parentId column.

I am still having trouble with the index column. I found the following information:

http://community.jboss.org/wiki/Bidirectionalone-to-manywithanindexedcollection?cmd=diffhist

Is it true that indexed collections do not support inverse="true" on the collection side?


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.