Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"




 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic