There are two possibilities here. First, your database supports optimistic locking in which case you can specify that in your *-ds.xml file. Second, you are using Hibernate for persistence in which case it uses optimistic locking by default unless you can set the optimistic-lock mapping attribute to false. You can read more about optimistic-lock in the Hibernate docs.
Many thanks for the reply.
I'm using mysql.
So all I have to do is edit the datasource to make the cache use optimistic locking ? I probably should have said I meant in the cache ?
Which data provider are you using in MySQL? I know that InnoDB does not provide optimistic locking?
Cache? Nothing like throwing in yet another term. What cache are you thinking about? Are you perhaps thinking of the caching that Hibernate does, since Hibernate is used to implement JPA?
The datasource does not do any caching (except for perhaps prepared statements, but that is really being done by the database anyway). JBoss AS does maintain a connection pool of data sources, but that does not involve caching any data.
I was referring to JBoss cache, I think I need to do something like this:
- or upgrade to 5.1 and use MVCC, but I had other problems upgrading the app to 5.0.
(obviously I'm getting deadlocks with pessimistic locking)