Hi,
I have a many-to-one relationship between LocationProfile and Address. Suppose I have Address1 referenced by LocationProfile1. I can successfully delete Address1, however if I try to search for all LocationProfiles right after that I receive the following exception:
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.mycompany.domain.model.Address#68]
You can see full stack trace at the end of this message.
The second line in the following code throws the exception:
Code:
addressDao.save(address);
persistedLocProfs = locationProfileDao.findAll(); // throws ObjectDeletedException
Here is how I define Address in LocationProfile.hbm.xml:
Code:
<many-to-one name="address" class="Address" cascade="save-update"/>
Here is how I define LocationProfile collection in Address.hbm.xml:
Code:
<set name="locationProfiles" cascade="delete" inverse="true">
<key column="address"/>
<one-to-many class="LocationProfile"/>
</set>
It seems that when I search for LocationProfiles (children) Hibernate tries to re-save deleted Address (parent) because child cascades save-update on the parent.
Any help will be greatly appreciated.
Thanks.
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.mycompany.domain.model.Address#68]
Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.mycompany.domain.model.Address#68]
at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1007)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:168)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:509)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:501)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:962)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1107)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at
...
com.mycompany.domain.dao.hibernate.GenericDaoImpl.findAll(Unknown Source)