# Optimistic locking problem

**URL:** <https://discourse.hibernate.org/t/optimistic-locking-problem/6915>\
**Category:** Hibernate ORM\
**Created:** [November 17, 2022, 9:03am UTC](https://discourse.hibernate.org/t/optimistic-locking-problem/6915 "2022-11-17T09:03:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Hornboll\_Hansen](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jan_hornboll_hansen/32/2118_2.png) [@Jan\_Hornboll\_Hansen](https://discourse.hibernate.org/u/Jan_Hornboll_Hansen)\
**Post date:** [November 17, 2022, 9:03am UTC](https://discourse.hibernate.org/t/optimistic-locking-problem/6915/1 "2022-11-17T09:03:11Z")

</div>

I have entity with @Version on an Instant column.  
I attach Entity through @OneToOne(cascade=persist) relationship (relation column in 2nd entity).  
When I flush hibernate does insert and update x set where id=? and modified=? and i get  
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1;  
There are no other threads/applications accessing database.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 21, 2022, 10:26am UTC](https://discourse.hibernate.org/t/optimistic-locking-problem/6915/2 "2022-11-21T10:26:27Z")

</div>

Please share a test case([hibernate-test-case-templates/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)) that reproduces the issue.
