-->
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.  [ 15 posts ] 
Author Message
 Post subject: deleted object would be re-saved by cascade
PostPosted: Tue May 11, 2004 9:20 am 
Newbie

Joined: Tue Apr 13, 2004 6:41 am
Posts: 19
I know this has been discussed couple times, but I still have one simple question:

What should I do to make Hibernaye deassociate object instead of throwing this exception (net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 2273119, of class: com.exigen.ipb.policy.infrastructure.QuoteSummaryJDO)?

I was thinking that setting cascade to "all" whould help but it is not helping. I am still getting same exception. Also as I understand "all" means that all children will be deleted when parent is deleted???

Rihards


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 2:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The problem is that you resave a deleted object.
Check your object graph and remove the deleted objects from the whole graph

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 8:59 am 
Newbie

Joined: Wed Sep 24, 2003 12:14 pm
Posts: 16
Location: Brazil
Hi!
I've the same problem...any hints here?
Thanks in advance.

_________________
Paulo Alvim
Powerlogic - Brazil


Top
 Profile  
 
 Post subject: Re: deleted object would be re-saved by cascade
PostPosted: Wed Jul 07, 2004 11:27 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
rihards wrote:
I know this has been discussed couple times, but I still have one simple question:

What should I do to make Hibernaye deassociate object instead of throwing this exception (net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 2273119, of class: com.exigen.ipb.policy.infrastructure.QuoteSummaryJDO)?

I was thinking that setting cascade to "all" whould help but it is not helping. I am still getting same exception. Also as I understand "all" means that all children will be deleted when parent is deleted???

Rihards


That probably means that the object you are trying to delete is a child of some other collection. Setting up cascade="all" for the object means that its children would be deleted/updated automatically unless they don't belong to some other parent.

you have to remove the object you are trying to delete for its parent collection.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 11:31 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
...FROM its parent collection

Example:

..............
objectBeingDeleted.getParent().getChildren().remove(objectBeingDeleted);
..............

and then you can do
.......
session.delete(objectBeingDeleted
.......


Top
 Profile  
 
 Post subject: Re: deleted object would be re-saved by cascade
PostPosted: Tue Sep 21, 2004 8:34 pm 
Newbie

Joined: Thu May 13, 2004 1:37 pm
Posts: 9
dime wrote:
That probably means that the object you are trying to delete is a child of some other collection. Setting up cascade="all" for the object means that its children would be deleted/updated automatically unless they don't belong to some other parent.

you have to remove the object you are trying to delete for its parent collection.

I'm having the same problem and I am removing the child object from the parent collection.

The code --
Code:
for (Iterator ip = team.getPlayers().  iterator(); ip.hasNext();) {
  Player player = (Player) ip.next();
  if (player.getName().equals("Open")) {
    Transaction tx = hibSession.beginTransaction();
    ip.remove();
    hibSession.save(team);
    hibSession.delete(player);
    tx.commit();
    continue;
  }
}


The tx.commit() throws the exception. Team is mapped as follows --
Code:
<hibernate-mapping package="">

    <class name="com.widget.Team" table="teams">

        <id name="id" column="id" type="java.lang.Integer">
            <generator class="identity"/>
        </id>
     
        <property name="name" column="name" type="java.lang.String" />
     
        <set name="players" cascade="all-delete-orphan" >
           <key column="teamid" />
           <one-to-many class="com.widget.Player" />
        </set>

    </class>
   
</hibernate-mapping>

After the exception is thrown, the row in the player table has teamid set to null. However, my expectation is that it would have been deleted since it's now orphaned.

Any help here? Thanks!![/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 6:37 pm 
Newbie

Joined: Mon Jan 23, 2006 11:44 pm
Posts: 15
Location: New Jersey, US
This is a real problem if we need to move children from one object to another.

We have a feature that split an object into more objects. Therefore, we need to create a new object and move some of the children from the original one to the new one. We don't have any solution but clone the children and delete the original copy of the children.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 6:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can avoid using delete orphan

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 4:05 am 
Newbie

Joined: Wed Nov 29, 2006 3:59 am
Posts: 6
I'm upgrading from 3.1.3 to 3.2.0 and I just started getting this problem.

Its true that the stuff I'm deleting is in collection already, but version 3.1.3 and earlier never gave me this problem, and everything worked (or at least Hibernate never throw this exception, still have to confirm did it actually work or not).

What changed since 3.1.3, and how to best fix all this? Was cascade checking improved and therefore I get an exception now or did the behavior change?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 4:13 am 
Newbie

Joined: Wed Nov 29, 2006 3:59 am
Posts: 6
I'm wondering if this has anything to do with new argument (transientEntities) in cascadeBeforeDelete() and cascadeAfterDelete() in DefaultDeleteEventListener (I have an event listener that extends it). What is it used for and what, if anything, am I supposed to be passing there?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 7:52 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Dynamo92, try doing:

for (Iterator ip = team.getPlayers(). iterator(); ip.hasNext();) {
Player player = (Player) ip.next();
if (player.getName().equals("Open")) {
Transaction tx = hibSession.beginTransaction();
ip.remove();
//hibSession.save(team);
hibSession.delete(player);
tx.commit();
continue;
}
}

And see if it works.

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 11:56 pm 
Newbie

Joined: Wed Nov 29, 2006 3:59 am
Posts: 6
I just went through my integration and HTML test, and its definitely the case that I was doing this before and it was working fine (I was deleting objects with Session.delete() while they were in some collection), and this is now throwing exception all over the place for me.

Could someone from Hibernate team explain what changed between 3.1.3 and 3.2.0?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 7:47 am 
Newbie

Joined: Thu Jan 11, 2007 7:19 am
Posts: 1
I'm using Hibernate 3.2. The way my app works is that I evict the parent object from the current Hibernate session; the subsequent deletion of the child object works fine (removing the child from a parent set will synchronize the foreign key to null, and most schemas will break when this occurs). The only thing you may have to be wary of is preloading the sets for the parent, since by default 3.2 lazy load is true. This can be done by invoking Hibernate.initialize on the collection (e.g., Hibernate.initialize(parent.getChildren())), usually in the DAO layer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 6:25 am 
Beginner
Beginner

Joined: Fri May 12, 2006 9:58 am
Posts: 32
emmanuel wrote:
you can avoid using delete orphan

This helped me solve the problem of moving a child from one parent to another.

I don't understand why all-delete-orphan was not appropriate though.
Could you please explain me why? Or point me to reference/book page?

thanks


Top
 Profile  
 
 Post subject: Re: deleted object would be re-saved by cascade
PostPosted: Tue Jun 19, 2012 4:33 am 
Newbie

Joined: Tue Jun 19, 2012 4:21 am
Posts: 1
I had a similar problem.
My situation is the following: i have two entity (Candidate and Job) and a many to many relation between them (Candidacies).
To delete an instance candidate of the entity Candidate:
    1. I have got the candidate
    2. I have cleared the elements of the list that represents the relations with one or more jobs
    3. I have made persistent the candidate
    4. I have removed succesfully the candidate
Here is my code:
Code:
         Candidate candidate = (Candidate) currentSession().get(Candidate.class, idCandidate);
         candidate.getCandidacies().clear();
         candidate = (Candidate) currentSession().merge(candidate);
         currentSession().delete(candidate);

I hope this helps someone
Best regards
Giordano


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