views:

325

answers:

1

We're developing a WebSite that's intended to 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 comes to any of the pages, some action checks for information in the DB to fill the requested page (that info consists of several entities, some of them with collections mapped, some lazy, some eager); it's all working fine until we receive several (not much... 2 is enough XD) concurrent requests, then hibernate throws an "OptimisticLockException" when fetching that info.

The funniest thing about this is that we're only reading info!! never writing!!

Maybe we've overlooked something or something like that... any help will be appreciated.

Thanks in advance.

+3  A: 

Maybe your transaction control is faulty. If you are using open-session in view, be sure to set the transaction to read-only, otherwise if you do obj.setXX() it will raise a change and hibernate will try to update the table.

Take a look at the configurations of your transactions isolation strategy as well.

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

kvalcanti
Sounds pretty probably what's happening... I'm starting to hate JPA... I'm feeling like it's a pair of coffins plus a chain with ultra-safe locks and on top of that being in jail, in what I can do with database connection and querying...
Juan Manuel