EntityManager.find(...) with pessimistic lock never throws LockTimeoutException [message #963249] |
Mon, 29 October 2012 13:24  |
Eclipse User |
|
|
|
In my code I set a pessimistic lock on a table row with following code:
Map<String,Object> properties = new HashMap<String, Object>();
properties.put("javax.persistence.lock.timeout", 2000);
// GetEm() returns the currently used entity manager
getEm().find(objClass, id, LockModeType.PESSIMISTIC_WRITE, properties);
This works and the lock is really set, but if an other client tries to set a lock on the same row the LockTimeoutException is never thrown, it just hangs on the find(...) method call until the other client releases the lock (which can be up to 5 minutes).
What am I doing wrong here? I found the same example at several places always always with the comment that this exception will be thrown...
I'm using
EclipseLink 2.4.1 (also didn't work with 2.3.2)
Postgresql
javax.Persistence 2.0.4
|
|
|
|
|
Re: EntityManager.find(...) with pessimistic lock never throws LockTimeoutException [message #965975 is a reply to message #964756] |
Wed, 31 October 2012 12:56  |
Eclipse User |
|
|
|
The following sql statement is executed:
SELECT ... WHERE (ID = ?) FOR UPDATE
which is blocking.
Like that:
SELECT ... WHERE (ID = ?) FOR UPDATE NOWAIT
it would be none blocking, but returning directly on failure.
It seems like postgresql doesn't support any locking timeout (thanks for the hint james).
It supports a statement_timeout, but unfortunately it isn't implemented in the JDBC driver.
Seems like it is not a eclipselink issue, but it would be nice, if there is a comment or something in the documentation, which states that the timeout isn't supported on all databases, it would have led me in the right direction of search...
I will try to get it work with the statement_timeout, something like:
java.sql.Connection cn = getEm().unwrap(java.sql.Connection.class);
cn.createStatement().execute("SET statement_timeout TO 1000");
|
|
|
Powered by
FUDForum. Page generated in 0.03741 seconds