-->
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.  [ 2 posts ] 
Author Message
 Post subject: StaleObjectStateException while saving a child copy
PostPosted: Wed Oct 14, 2009 11:53 am 
Newbie

Joined: Mon Dec 25, 2006 4:59 am
Posts: 15
Hi Guys

I am facing a staleobjectException in the following flow:

1. loading A entity
2. copying A entity with new unique id
3. adding copied entity as a child to new B entity.
4. saving B entity
5. on session flush org.hibernate.StaleObjectStateException is thrown

All of the above actions are wrapped in transaction, provided by Spring's TransactionInterceptor

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction
(or unsaved-value mapping was incorrect): at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1635)

Code:
<hibernate-mapping package="com.something.domain.B"
   default-access="field">

   <class name="EntityB" table="ENTITYB" dynamic-insert="true" lazy="false">

      <cache usage="read-write" />
      <id name="id" column="B_ID" />
      <property name="updateDate" column="UPDATEDDATE" type="timestamp" />
      
      <many-to-one name="reportInfo" class="com.something.domain.A" column="A_ID"
         cascade="save-update" />
   </class>      
</hibernate-mapping>


Code:
<hibernate-mapping package="com.something.domain.A"
   default-access="field">

   <class name="EntityA" table="ENTITYA" dynamic-insert="true" lazy="false">

      <cache usage="read-write" />

      <id name="id" column="A_ID" />
   </class>
</hibernate-mapping>


thx


Top
 Profile  
 
 Post subject: Re: StaleObjectStateException while saving a child copy
PostPosted: Tue Oct 19, 2010 6:10 pm 
Newbie

Joined: Wed Oct 06, 2010 1:35 pm
Posts: 6
I am facing exactly the same problem (or something close). I have a "Header" object, an intermediate "Group" object and a "Detail" object. All the objects are defined with cascading @OneToMany relationships, e.g.:


@OneToMany(mappedBy = "header", cascade=CascadeType.ALL)
private List<Group> vehicles = new ArrayList<Group>();

I am getting StaleObjectException errors all over the place! It seems to be related to the entire object "tree" being saved any time any object is updated, so if you have two updated objects in your "tree" (two detail objects for example), the first update goes fine but the second update finds an already-updated row and throws the exception.

I was kind of hoping Hibernate would eliminate this kind of problem. Can anyone help?


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.