Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EntityManager.find(...) with pessimistic lock never throws LockTimeoutException
EntityManager.find(...) with pessimistic lock never throws LockTimeoutException [message #963249] Mon, 29 October 2012 17:24 Go to next message
Yennor - is currently offline Yennor -
Messages: 2
Registered: October 2012
Junior Member
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 #964621 is a reply to message #963249] Tue, 30 October 2012 17:11 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1023
Registered: July 2009
Senior Member
What database platform are you using?
Can you turn on logging and see what the SQL that gets executed is? Does this work on a JPQL query?

Best Regards,
Chris
Re: EntityManager.find(...) with pessimistic lock never throws LockTimeoutException [message #964756 is a reply to message #964621] Tue, 30 October 2012 19:28 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Not all databases support lock/query timeouts. Check that Postgresql can support this.


James : Wiki : Book : Blog : Twitter
Re: EntityManager.find(...) with pessimistic lock never throws LockTimeoutException [message #965975 is a reply to message #964756] Wed, 31 October 2012 16:56 Go to previous message
Yennor - is currently offline Yennor -
Messages: 2
Registered: October 2012
Junior Member
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");
Previous Topic:NPE in CascadeLockingPolicy.initUnmappedFieldsQuery
Next Topic:The attribute type must implement the Serializable interface.
Goto Forum:
  


Current Time: Fri Sep 19 20:07:22 GMT 2014

Powered by FUDForum. Page generated in 0.09261 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software