File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate -  ObjectDeletedException: deleted object would be re-saved by cascade... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate -  ObjectDeletedException: deleted object would be re-saved by cascade..." Watch "Hibernate -  ObjectDeletedException: deleted object would be re-saved by cascade..." New topic
Author

Hibernate - ObjectDeletedException: deleted object would be re-saved by cascade...

Ally Cavs
Ranch Hand

Joined: Aug 25, 2008
Posts: 89
Hi

I have a parent class(Person) and a child class (UploadedFile)
All updates, inserts work fine but deletes do not. I get this error

i get this error
ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)

if this is called
person.getPhotos.remove(0);
and then this is called
session.update(person)

Does the child UploadedFile need to have a person reference as this is what I see on the net?
But is there anyway to avoid this as I think it is over kill
I tried inverse="true" and insvers="false"




Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I found this

https://forum.hibernate.org/viewtopic.php?p=2350533

Are you removing the object from all collections?

It shouldn't be related to needing to make it bi-directional.

Usually the best approach is to remove the object from the collection, then update/save the parent object. The cascade option on the collection and Hibernate seeing it has been removed from the collection will tell hibernate to delete the removed object.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ally Cavs
Ranch Hand

Joined: Aug 25, 2008
Posts: 89
Hi Mark,

Yes i onky store the object in this collection.
Now i remove the object in one struts action
Another struts action handles the saving

So struts action 1
calls
person.getPhotos.remove(0);

while a second action calls
person.getPhotos.remove(0);

I dont think this is a problem
but I am really stumped at this issue. Can someone please show me what to do or a working example please?

Thanks
Ally
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate - ObjectDeletedException: deleted object would be re-saved by cascade...