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