• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ally Cavs
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ally Cavs
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic