-->
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: Many-to-one, moving child objects, ObjectDeletedException.
PostPosted: Fri Feb 27, 2009 3:02 am 
Beginner
Beginner

Joined: Sun Jan 11, 2009 2:47 pm
Posts: 21
hi,

i have a many-to-one association of A to B with inverse=true set on the many side (it's a Set). in my Java code, A contains a Set<B> and B contains a reference to an A. the cascade setting on the set is cascade="save-update,delete,delete-orphan". the mappings are included below ("ForumCategory" is the A and "Forum" is the B).

now in the code, i want to change the A that contains B to a different A. so i remove() the B instance from the old A's set, add it to the new A's set, and update the A reference in B to the new A. when i do this, hibernate throws an ObjectDeleteException that says "deleted object would be re-saved by cascade (remove deleted object from associations)".

i'm using direct field access, not property access, if that matters.

how do i make this work?

thanks!
j

Hibernate version:
3.2.2

Mapping documents:
Code:
   <class name="forum.Forum" table="forums">
      <id name="id" column="forum_id"><generator class="native"/></id>
      <property name="name" not-null="true"/>
      <many-to-one name="category" column="category_id" class="forum.ForumCategory" not-null="true"/>
      <property name="created" not-null="true"/>
   </class>
   
   <class name="forum.ForumCategory" table="categories">
      <id name="id" column="category_id"><generator class="native"/></id>
      <property name="name" not-null="true"/>
      <set name="forums" inverse="true" cascade="save-update,delete,delete-orphan">
         <key column="category_id"/>
         <one-to-many class="forum.Forum"/>
      </set>
      <property name="created" not-null="true"/>
   </class>


Full stack trace of any exception that occurs:
Code:
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [forum.Forum#2]
   org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1018)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:165)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:511)
   org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:503)
   org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
   org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
   org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
   org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
   org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
   org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
   org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   org.hibernate.engine.Cascade.cascade(Cascade.java:130)
   org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
   org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
   org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
   org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
   org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1004)
   org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:342)
   org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:136)
   forum.db.HibernateUtil.commitTransaction(HibernateUtil.java:58)
   forum.db.DBTransactionFilter.doFilter(DBTransactionFilter.java:80)


Name and version of the database you are using:
MS SQL Server 2005


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.