-->
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.  [ 7 posts ] 
Author Message
 Post subject: cascade all-delete-orphan
PostPosted: Mon Dec 08, 2003 1:21 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I can't seem to get deletes to cascade to orphaned rows in an application.

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
  <class name="com.bla.mytable.MyTableGroup" table="MYTABLEGROUP">
    <id column="MYTABLEGROUPID" name="myTableGroupId" type="long">
      <generator class="native" />
    </id>
    <version column="UPDATECOUNT" type="int" name="updateCount" />
    <property column="INTERFACED" length="1" name="interfaced" not-null="true" type="yes_no" />
    <many-to-one name="applyingUser" column="APPLYINGUSER" not-null="true" class="com.bla.User" />
    <set name="myTableHeader" inverse="true" cascade="all-delete-orphan">
      <key column="MYTABLEGROUPID" />
      <one-to-many class="com.bla.mytable.MyTableHeader" />
    </set>
  </class>

  <class name="com.bla.mytable.MyTableHeader" table="MYTABLEHEADER">
    <id column="MYTABLEHEADERID" name="myTableHeaderId" type="long">
      <generator class="native" />
    </id>
    <version column="UPDATECOUNT" type="int" name="updateCount" />
    <many-to-one name="myTableGroup" column="MYTABLEGROUPID" class="com.bla.mytable.MyTableGroup" />
  </class>
</hibernate-mapping>


In debug, I can see that it is running the delete properly but the Set of orphans is empty. Cascaded updates and adds work fine. The id is a java.lang.Long.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 1:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Be more specific, add a simple testcase including executed code
http://www.hibernate.org/ForumMailinglists/HowToAskForHelp

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 2:58 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I realize I was pretty brief. I should have mentioned in my message that a complete example is forthcoming. The test cases I could submit right now all rely on DB2 running on an iSeries so I will build something that works with MySql. I just wanted to get an opinion in the mean time on whether I mapped it correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 3:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No need to migrate it.
What is really needed is:
- the code between openSession and session.close()
- the mapping (btw your's looks fine)
- hibernate logs
- the pb you faced

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 5:21 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I have been able to confirm that the mapping is OK. For some reason what I would have assumed is a collection insert is running before previous collection deletes. If I delete a row that triggers an all-delete-orphan in a collection I thought it was supposed to run the delete before the insert. I added a flush.

Here is what the manual says:

1. all entity insertions, in the same order the corresponding objects were saved using Session.save()
2. all entity updates
3. all collection deletions
4. all collection element deletions, updates and insertions
5. all collection insertions
6. all entity deletions, in the same order the corresponding objects were deleted using Session.delete()


I think I have 5 running before 3 but it acts like an all-delete-orphan is a 6.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 7:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
An "orphan" is an entity! Its *really* important to understand the difference b/w an entity type and a value type. You won't understand anything in Hibernate without understanding this!

Entity insertions occur before entity deletions.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 1:37 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
Thanks for the help; that matches what I observed. I jumped to the conclusion that entities in a collection followed collection rules. It didn't occur to me a collection might contain value types because I have not ever needed to map a simple value to a Hibernate collection.


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