-->
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.  [ 6 posts ] 
Author Message
 Post subject: Confused about all-delete-orphan option
PostPosted: Tue Nov 25, 2003 8:24 pm 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
Hello, all!

I am a bit confused about this option. Basically, if I say inverse="false" and cascade="all-delete-orphan' the orphan deletion reverts to the regular behavior of just nulling the keys.

To me it just does not make much sense. Since if the orphan is deleted it is not really necessary to update the keys, the same delete should be executed in my opinion one correctly execute if the inverse="true"

Can someone explain the reason for the behavior above?

Thanks,
Alex.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 8:59 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
1. accordind to documentation, inverse does not affect cascading
2. could you paste your mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 9:24 pm 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
<hibernate-mapping>
<class name="model.Parent" table="parent"
dynamic-update="false" dynamic-insert="false">

<id name="parentId" column="parent_id" type="java.lang.Long">
<generator class="native">
</generator>
</id>

<list name="children" lazy="true" inverse="false" cascade="all-delete-orphan">
<key column="parent_id" />
<index column="child_no" />
<one-to-many class="model.Child" />
</list>
<property name="name" type="java.lang.String"
update="true" insert="true" column="name" />
</class>

<class name="model.Child" table="child"
dynamic-update="false" dynamic-insert="false">

<composite-id>
<key-property name="childNo" column="child_no" />
<key-many-to-one name="parent" class="model.Parent" column="parent_id" />
</composite-id>

<property name="name" type="java.lang.String"
update="true" insert="true" column="child_name" />

</class>

</hibernate-mapping>


and here is my test:

[code]
Session s = sessions.openSession();

Parent p = (Parent) s.load (Parent.class, new Long (1));
Child c0 = null;

Iterator iter = p.getChildren().iterator ();
int i = 0;
while (iter.hasNext()) {
if (i == 1) {
c0 = (Child) iter.next ();
iter.remove ();
break;
}
i++;
}

s.flush ();
s.close();

s = sessions.openSession();
p = (Parent) s.load (Parent.class, new Long (1));

iter = p.getChildren().iterator ();
i = 0;
while (iter.hasNext()) {
Child c = (Child) iter.next ();
System.out.println (c.getName () + "[" + c.getChildNo() + "] - [" + i + "]");
i++;
}

s.flush ();
s.close();
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 10:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you specify inverse="false", Hibernate will null the FKs before deleting. I can't think why you would have inverse="false" with all-delete-orphan - it doesn't seem to be a very sensible combination.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 10:16 pm 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
actually it goes all the way to my other post, where I was having problem with lists.

Setting inverse="false" seems to be the only way hibernate puts the right indecies in my case child_no into the database. Since, I also need to have all-delete-orphan there seems to be a catch 22. Is there any other way to get the indecies to be populated correctly?

Thanks,
Alex.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 10:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not supported.


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