-->
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.  [ 1 post ] 
Author Message
 Post subject: One-to-many deleted object would be re-saved by cascade
PostPosted: Sun Jan 31, 2010 3:21 pm 
Newbie

Joined: Sun Jan 31, 2010 2:29 pm
Posts: 1
I have one-to-many relationship between Person and ContactEntry classes. My hibernate version is 3.3.2.GA.

Person class has Set of ContactEntry.

I create objects as follows, which works fine.
sessionFactory.getCurrentSession().save(person);
for each contactEntry {
sessionFactory.getCurrentSession().save (contactEntry);
person.addContact(contactEntry);
}
sessionFactory.getCurrentSession().update(person);

I remove one of the contactEntry as in the following psudo code
contactEntry = person.getContact().iterator().next();
person.removeContact(contactEntry);
sessionFactory.getCurrentSession().delete(contactEntry);

I am executing junit test with SpringJUnit4ClassRunner.

If I do the creation and removal of one contactEntry in two different tests everything works perfectly. However if I do it in the same test, I get
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations).

Following is the trace

BUT... IF I do evict on person anytime before deleting contactEntry...it's okay with hibernate!

[junit] Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [in.opencombine.communication.E_ContactEntry#165]
[junit] at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1042)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:188)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
[junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
[junit] at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
[junit] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
[junit] at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
[junit] at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:292)
[junit] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:240)
[junit] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:193)
[junit] at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:320)
[junit] at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:266)
[junit] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:243)
[junit] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:193)
[junit] at org.hibernate.engine.Cascade.cascade(Cascade.java:154)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
[junit] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
[junit] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
[junit] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
[junit] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
[junit] at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)


hbm-configurations are as follows -
<class
name="in.opencombine.life.Person"
table="PERSON"
dynamic-update="true">

<!-- Technical ID -->
<id name="id" type="string" unsaved-value="null" column="ID">
<generator class="assigned"/>
</id>

<version name="version" column="VERSION" unsaved-value="null"/>

<property name="birthday" not-null="true" column="BIRTHDAY" />

<property name="sex" column="SEX" type="SexOfBeings" />

<property name="demiseday" column="DEMISEDAY" />

<!-- Associations -->

<set name="contacts" table="CONTACT_ENTRY" lazy="false" cascade="all" inverse="true">
<key column="CONTACTABLE" />
<one-to-many class="in.opencombine.communication.ContactEntry" />
</set>
</class>

<class name="in.opencombine.communication.ContactEntry" table="CONTACT_ENTRY" dynamic-update="true" polymorphism="implicit" >

<!-- Technical ID -->
<id name="id" type="long" unsaved-value="null" column="ID">
<generator class="native"/>
</id>

<!-- Properties -->
<version name="version" column="VERSION" />

<property name="tag" column="TAG" />

<!-- Associations -->

<many-to-one name="contactable"
column="CONTACTABLE" not-null="false"
class="in.opencombine.life.Person"
/>

<joined-subclass name="in.opencombine.communication.AddressContactEntry" table="ADDRESS_CONTACT_ENTRY">
<key column="id"/>
<many-to-one name="address"
column="ADDRESS" cascade="persist,merge,save-update" not-null="true"
class="in.opencombine.places.Address"
/>
</joined-subclass>

<joined-subclass name="in.opencombine.communication.E_ContactEntry" table="E_CONTACT_ENTRY">
<key column="id"/>
<many-to-one name="eContact"
column="E_CONTACT" cascade="persist,merge,save-update" not-null="true"
class="in.opencombine.communication.E_Contact"
/>
</joined-subclass>

<joined-subclass name="in.opencombine.communication.TelephoneContactEntry" table="TELEPHONE_CONTACT_ENTRY">
<key column="id"/>
<many-to-one name="telephone"
column="TELEPHONE" cascade="save-update" not-null="true"
class="in.opencombine.communication.Telephone"
/>
</joined-subclass>

</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.