Hi grainne,
thanks for replying my message. I was begining to think this forum was only for people who already knew everything about hibernate! Anyway, I applied the changes you suggested, I am surprised that the information you mention is so incorrect, but i am still getting the same error message:
19:37:17,070 DEBUG SessionImpl:528 - opened session
19:37:17,074 DEBUG JDBCTransaction:37 - begin
19:37:17,077 DEBUG JDBCTransaction:41 - current autocommit status:false
19:37:17,079 DEBUG Cascades:408 - version unsaved-value strategy NEGATIVE
19:37:17,081 DEBUG SessionImpl:1326 - saveOrUpdate() previously saved instance with id: 123456
19:37:17,083 DEBUG SessionImpl:1374 - updating [test.Order#123456]
19:37:17,093 DEBUG SessionImpl:1221 - collection dereferenced while transient [test.Order.OrderItems#123456]
19:37:17,101 DEBUG Cascades:497 - processing cascades for: test.Order
19:37:17,103 DEBUG Cascades:524 - cascading to collection: test.Order.OrderItems
19:37:17,106 DEBUG Cascades:113 - cascading to saveOrUpdate()
19:37:17,108 DEBUG Cascades:408 - version unsaved-value strategy NEGATIVE
19:37:17,110 DEBUG SessionImpl:1321 - saveOrUpdate() unsaved instance
19:37:17,113 DEBUG SessionImpl:786 - saving [test.OrderItem#654321]
19:37:17,115 DEBUG Cascades:312 - id unsaved-value: id_value
19:37:17,124 DEBUG Cascades:506 - done processing cascades for: test.Order
19:37:17,126 DEBUG JDBCTransaction:59 - commit
19:37:17,128 DEBUG SessionImpl:2193 - flushing session
19:37:17,130 DEBUG Cascades:497 - processing cascades for: test.Order
19:37:17,132 DEBUG Cascades:524 - cascading to collection: test.Order.OrderItems
19:37:17,134 DEBUG Cascades:113 - cascading to saveOrUpdate()
19:37:17,137 DEBUG SessionImpl:1306 - saveOrUpdate() persistent instance
19:37:17,139 DEBUG Cascades:506 - done processing cascades for: test.Order
19:37:17,140 DEBUG SessionImpl:2321 - Flushing entities and processing referenced collections
19:37:17,143 DEBUG WrapVisitor:76 - Wrapped collection in role: test.Order.OrderItems
19:37:17,146 DEBUG SessionImpl:2415 - Updating entity: [test.Order#123456]
19:37:17,148 DEBUG Versioning:26 - Incrementing: 0 to 1
19:37:17,154 DEBUG SessionImpl:2768 - Collection found: [test.Order.OrderItems#123456], was: [<unreferenced>]
19:37:17,156 DEBUG SessionImpl:2664 - Processing unreferenced collections
19:37:17,158 DEBUG SessionImpl:2678 - Scheduling collection removes/(re)creates/updates
19:37:17,174 DEBUG SessionImpl:2217 - Flushed: 1 insertions, 1 updates, 0 deletions to 2 objects
19:37:17,176 DEBUG SessionImpl:2222 - Flushed: 1 (re)creations, 0 updates, 1 removals to 1 collections
19:37:17,179 DEBUG Printer:75 - listing entities:
19:37:17,182 DEBUG Printer:82 - test.Order{OrderDate=19 October 2004 19:37:09, PriceTotal=4.99, UserID=1, OrderItems=[OrderItem#654321], version=1, ID=123456}
19:37:17,184 DEBUG Printer:82 - test.OrderItem{Stock=Stock#d1e22501fbf2ece300fbf2efe1440001, Amount=1, OrderID=123456, Price=4.99, Order=Order#123456, StockID=d1e22501fbf2ece300fbf2efe1440001, version=-1, ID=654321}
19:37:17,186 DEBUG SessionImpl:2258 - executing flush
19:37:17,188 DEBUG EntityPersister:454 - Inserting entity: [test.OrderItem#654321]
19:37:17,191 DEBUG EntityPersister:455 - Version: -1
19:37:17,193 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
19:37:17,195 DEBUG SQL:223 - insert into orderitemstbl (version, amount, price, order_id, stock_id, orderitem_id) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into orderitemstbl (version, amount, price, order_id, stock_id, orderitem_id) values (?, ?, ?, ?, ?, ?)
19:37:17,197 DEBUG BatcherImpl:227 - preparing statement
19:37:17,200 DEBUG EntityPersister:389 - Dehydrating entity: [test.OrderItem#654321]
19:37:17,203 DEBUG Cascades:312 - id unsaved-value: id_value
19:37:17,205 DEBUG BatcherImpl:28 - Adding to batch
19:37:17,207 DEBUG BatcherImpl:50 - Executing batch size: 1
19:37:17,259 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
19:37:17,261 DEBUG BatcherImpl:240 - closing statement
19:37:17,263 DEBUG EntityPersister:631 - Updating entity: [test.Order#123456]
19:37:17,265 DEBUG EntityPersister:632 - Existing version: 0 -> New version: 1
19:37:17,268 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
19:37:17,270 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=?
19:37:17,273 DEBUG BatcherImpl:227 - preparing statement
19:37:17,275 DEBUG EntityPersister:389 - Dehydrating entity: [test.Order#123456]
19:37:17,326 ERROR StaleObjectStateException:27 - An operation failed due to stale data
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for test.Order instance with identifier: 123456
The problem is the many-to-one Set association (OrderItems) being updated which is dirty which is causing the trouble. From the Hibernate manual, I understand what is doing, what I want to do is find a solution for this. Any ideas anybody???
thanks in advance
Andrew
|