I use Hibernate optimistic locks in my software (via @Version annotation). It works quite well, but sometimes I get StaleObjectStateException while trying to merely retrieve some objects from database. How can I prevent Hibernate from throwing these exceptions?
I use Hibernate optimistic locks in my software (via @Version annotation). It works quite
Share
I’d guess you change some Object in your Session. Then you execute a query, which flushes the session. Since the object is already changed by somebody else you get the Exception.
Solutions: Difficult. You could loop through the contents of your session before executing the query and print out everything that is dirty, in order to find the object that is causing the trouble.