I've also run into the exact same issue with Version 5.2.12 and I've created a test case that hopefully helps to resolve the issue soon. So far the only solution is indeed to flush the entity manager before doing the query. I've run into this issue while using Hibernate to implement the repository of a DDD aggregate where the transaction spans not only the aggregate but the whole bounded context (my use case doesn't allow for eventual consistency ). What happens then is that in some part of the domain logic, the entity/aggregate is created. A bit later, still in the same transaction, a service wants to modify this aggregate/entity and loads it from the repository/hibernate with PESSIMISTIC_WRITE. This causes the exception to be thrown. |