OptimisticLockException exception while trying to get data from postgreSQL

We are developing WebSite, which should have several requests per second.

Our current environment is JavaEE, JBoss 4.2.3, Struts2 for MVC, JPA with Hibernate as ORM and Postgres as DB.-

This is the scenario: whenever a request arrives on any of the pages, some actions check the information in the database to fill in the requested page (this information consists of several objects, some of them with matching collections, some are lazy, some tend to); everything works fine until we get several (not many ... 2 enough XD) simultaneous requests, and then hibernate throws an "OptimisticLockException" when this information is received.

The funny thing about this is that we only read information! never wrote!

Maybe we missed something or something like that ... any help would be appreciated.

Thanks in advance.

+4
source share
1 answer

Your transaction control may be defective. If you use open-session in the view, be sure to set the transaction to be read-only, otherwise, if you execute obj.setXX (), it will raise the change and hibernate will try to update the table.

See also the configuration of transaction isolation strategies.

Finnaly, be sure to correctly return the version attribute, as well as its display; and equals and hashcode (especially when using collections).

+3
source

All Articles