-->
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.  [ 4 posts ] 
Author Message
 Post subject: Row was updated or deleted by another transaction....
PostPosted: Tue Oct 19, 2004 6:08 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
(or unsaved-value mapping was incorrect) for test.OrderItem instance with identifier: 654321

Hi,
I am getting the above mentioned error message when trying to save a parent/child association. Could anyone please tell me what i am doing incorrectly?

many thanks


Andrew

Hibernate version:2.1.1

Mapping documents:
Order.hbm.xml

<class name="Order" table="orderstbl">
<id name="ID" column="order_id">
<generator class="assigned"/>
</id>
<version name="Version" column="version" unsaved-value="null"/>
<property name="PriceTotal" column="price_total" type="double" not-null="true"/>
<property name="OrderDate" column="order_date" type="timestamp" not-null="true"/>
<property name="UserID" column="user_id" type="integer" not-null="true"/>
<set name="OrderItems" table="orderitemstbl" inverse="true" cascade="all-delete-orphan">
<key column="order_id"/>
<one-to-many class="OrderItem"/>
</set>

</class>

OrderItem.hbm.xml

<class name="OrderItem" table="orderitemstbl">
<id name="ID" column="orderitem_id">
<generator class="assigned"/>
</id>
<version name="Version" column="version" unsaved-value="null"/>
<property name="OrderID" column="order_id" type="string" not-null="true" insert="false" update="false"/>
<property name="StockID" column="stock_id" type="string" not-null="true" insert="false" update="false"/>
<property name="Amount" column="amount" type="integer"/>
<property name="Price" column="price" type="double"/>

<many-to-one name="Order" class="Order" column="order_id" />
<many-to-one name="Stock" class="Stock" column="stock_id"/>

</class>


Code between sessionFactory.openSession() and session.close():

Order.Class

transaction = session.beginTransaction();

session.save(myOrder);

transaction.commit();
Util.closeSession();


Full stack trace of any exception that occurs:

net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for test.OrderItem instance with identifier: 654321
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:505)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:655)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:625)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2262)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at test.Order.newOrder(Order.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:230)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:1105)
at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:190)
at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:138)
at org.mozilla.javascript.continuations.InterpretedFunctionImpl.call(InterpretedFunctionImpl.java:121)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
at org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java:1591)
at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.handleContinuation(FOM_JavaScriptInterpreter.java:799)
at org.apache.cocoon.components.treeprocessor.sitemap.CallFunctionNode.invoke(CallFunctionNode.java:150)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:165)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:162)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:136)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:371)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:312)
at org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(MountNode.java:133)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:165)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:162)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:136)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:371)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:312)
at org.apache.cocoon.Cocoon.process(Cocoon.java:656)
at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:324)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:395)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:673)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:615)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:786)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:552)
10:31:13,756 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
10:31:13,759 DEBUG BatcherImpl:240 - closing statement
10:31:13,761 ERROR SessionImpl:2269 - Could not synchronize database state with session
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for test.OrderItem instance with identifier: 654321
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:505)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:655)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:625)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2262)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at test.Order.newOrder(Order.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:230)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:1105)
at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:190)
at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:138)
at org.mozilla.javascript.continuations.InterpretedFunctionImpl.call(InterpretedFunctionImpl.java:121)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
at org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java:1591)
at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.handleContinuation(FOM_JavaScriptInterpreter.java:799)
at org.apache.cocoon.components.treeprocessor.sitemap.CallFunctionNode.invoke(CallFunctionNode.java:150)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:165)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:162)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:136)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:371)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:312)
at org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(MountNode.java:133)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:84)
at org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.invoke(PreparableMatchNode.java:165)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:162)
at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:107)
at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:136)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:371)
at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:312)
at org.apache.cocoon.Cocoon.process(Cocoon.java:656)
at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:324)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:395)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:673)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:615)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:786)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:552)




Name and version of the database you are using:

The generated SQL (show_sql=true):
10:31:13,588 DEBUG Cascades:497 - processing cascades for: test.Order
10:31:13,589 DEBUG Cascades:524 - cascading to collection: test.Order.OrderItems
10:31:13,591 DEBUG Cascades:113 - cascading to saveOrUpdate()
10:31:13,594 DEBUG SessionImpl:1306 - saveOrUpdate() persistent instance
10:31:13,596 DEBUG Cascades:506 - done processing cascades for: test.Order
10:31:13,598 DEBUG SessionImpl:2321 - Flushing entities and processing referenced collections
10:31:13,600 DEBUG WrapVisitor:76 - Wrapped collection in role: test.Order.OrderItems
10:31:13,602 DEBUG AbstractEntityPersister:278 - test.Order.OrderItems is dirty
10:31:13,608 DEBUG SessionImpl:2415 - Updating entity: [test.Order#123456]
10:31:13,612 DEBUG Versioning:26 - Incrementing: 0 to 1
10:31:13,619 DEBUG SessionImpl:2768 - Collection found: [test.Order.OrderItems#123456], was: [<unreferenced>]
10:31:13,623 DEBUG SessionImpl:2415 - Updating entity: [test.OrderItem#654321]
10:31:13,625 DEBUG Versioning:26 - Incrementing: 0 to 1
10:31:13,627 DEBUG SessionImpl:2664 - Processing unreferenced collections
10:31:13,630 DEBUG SessionImpl:2678 - Scheduling collection removes/(re)creates/updates
10:31:13,639 DEBUG SessionImpl:2217 - Flushed: 1 insertions, 2 updates, 0 deletions to 2 objects
10:31:13,641 DEBUG SessionImpl:2222 - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
10:31:13,654 DEBUG Printer:75 - listing entities:
10:31:13,657 DEBUG Printer:82 - test.Order{OrderDate=19 October 2004 10:30:58, PriceTotal=4.99, UserID=1, Version=1, OrderItems=[OrderItem#654321], ID=123456}
10:31:13,659 DEBUG Printer:82 - test.OrderItem{Stock=Stock#d1e22501fbf2ece300fbf2efe1440001, Amount=1, OrderID=123456, Price=4.99, Version=0, Order=Order#123456, StockID=d1e22501fbf2ece300fbf2efe1440001, ID=654321}
10:31:13,661 DEBUG SessionImpl:2258 - executing flush
10:31:13,663 DEBUG EntityPersister:454 - Inserting entity: [test.Order#123456]
10:31:13,665 DEBUG EntityPersister:455 - Version: 0
10:31:13,667 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
10:31:13,669 DEBUG SQL:223 - insert into orderstbl (version, price_total, order_date, user_id, order_id) values (?, ?, ?, ?, ?)
Hibernate: insert into orderstbl (version, price_total, order_date, user_id, order_id) values (?, ?, ?, ?, ?)
10:31:13,671 DEBUG BatcherImpl:227 - preparing statement
10:31:13,674 DEBUG EntityPersister:389 - Dehydrating entity: [test.Order#123456]
10:31:13,677 DEBUG BatcherImpl:28 - Adding to batch
10:31:13,679 DEBUG BatcherImpl:50 - Executing batch size: 1
10:31:13,686 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
10:31:13,688 DEBUG BatcherImpl:240 - closing statement
10:31:13,690 DEBUG EntityPersister:631 - Updating entity: [test.Order#123456]
10:31:13,692 DEBUG EntityPersister:632 - Existing version: 0 -> New version: 1
10:31:13,694 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
10:31:13,696 DEBUG SQL:223 - update orderstbl set version=?, price_total=?, order_date=?, user_id=? where order_id=? and version=?
Hibernate: update orderstbl set version=?, price_total=?, order_date=?, user_id=? where order_id=? and version=?
10:31:13,698 DEBUG BatcherImpl:227 - preparing statement
10:31:13,701 DEBUG EntityPersister:389 - Dehydrating entity: [test.Order#123456]
10:31:13,706 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
10:31:13,708 DEBUG BatcherImpl:240 - closing statement
10:31:13,710 DEBUG EntityPersister:631 - Updating entity: [test.OrderItem#654321]
10:31:13,712 DEBUG EntityPersister:632 - Existing version: 0 -> New version: 1
10:31:13,714 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
10:31:13,716 DEBUG SQL:223 - update orderitemstbl set version=?, amount=?, price=?, order_id=?, stock_id=? where orderitem_id=? and version=?
Hibernate: update orderitemstbl set version=?, amount=?, price=?, order_id=?, stock_id=? where orderitem_id=? and version=?
10:31:13,718 DEBUG BatcherImpl:227 - preparing statement
10:31:13,720 DEBUG EntityPersister:389 - Dehydrating entity: [test.OrderItem#654321]
10:31:13,723 DEBUG Cascades:312 - id unsaved-value: id_value
10:31:13,740 ERROR StaleObjectStateException:27 - An operation failed due to stale data


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: As a follow on..
PostPosted: Tue Oct 19, 2004 10:49 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
would I need to explicitly save the child to overcome the initial problem I was having? Does anyone have a solution to this problem?


thanks


Andrew


Top
 Profile  
 
 Post subject: adding more to the pot...
PostPosted: Tue Oct 19, 2004 12:43 pm 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
i have discovered the following class, StaleObjectStateException.java, written by gavin King which states that:

'* Note that this exception often indicates that the user failed to specify the
* correct <tt>unsaved-value</tt> strategy for a class'

Ok... I have specified a version tag in my map:
<version name="Version" column="version" type="integer" unsaved-value="null"/>

which should determine whether an object is transient or persistant, right!?


Andrew


Top
 Profile  
 
 Post subject: On further reading of the Hibernate in Action book page 171
PostPosted: Tue Oct 19, 2004 1:35 pm 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
I came across this snippet:

'Is the version of the parent updated if a child is modified? For example, if a single bid in the collection bids of an Item is modified, is the version number of the Item also increased by one or not? The answer to that and similar questions is simple: Hibernate will increment the version number whenever an object is dirty. This includes all dirty properties, whether they


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.