1
org.hibernate.StaleStateException 

Is thrown sometimes (not consistent) in unit test case.

The normal flow is:

  1. Create
  2. Update
  3. Delete

StaleStateException is thrown while executing delete operation.

The entity has child entities with one to many relationship:

<set name="child" cascade="delete, all,delete-orphan" inverse="true"
      lazy="true">
      <cache usage="nonstrict-read-write"/>
      <key column="COLUMN"/>
      <one-to-many class="CHILDClass"/>
    </set>

And the cache strategy is "nonstrict-read-write"

Not sure of its issue due to second level cache, as the exception is not consistent. How to fix this issue and what extra details I need to check to fix this issue.

Gaurav
  • 3,615
  • 2
  • 27
  • 50
  • 1
    Add the full stack trace – Christian Beikov Oct 14 '21 at 05:56
  • Thanks @ChristianBeikov for reply, I dont have the complete stack now, will try to update the question. Just one link I found here is that it is due to the cache strategy, https://vladmihalcea.com/how-does-hibernate-nonstrict_read_write-cacheconcurrencystrategy-work/ – Gaurav Oct 14 '21 at 06:30
  • Usually `StaleStateException` means that you are trying to manage an instance with Hibernate that has not been attached to the Session. See if this answer can help https://stackoverflow.com/questions/44933587/batch-update-returned-unexpected-row-count-from-update-0/44997468#44997468 – gmanjon Nov 11 '21 at 10:29

0 Answers0