Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » javax.persistence.lock.timeout is beeing ignored...(... instead a PessimisticLockException is thrown after more than a minute)
javax.persistence.lock.timeout is beeing ignored... [message #548793] Fri, 23 July 2010 05:45 Go to next message
moritz du is currently offline moritz du
Messages: 98
Registered: February 2010
Member
at the moment a try to write code for editing database-entries using pessimistic locking.
my first test code looks like this:
EntityTransaction tx=em.getTransaction();
		tx.begin();
		Map<String,Object> props = new HashMap<String, Object>();
		props.put("javax.persistence.lock.timeout", 3000);
		em.lock(entry, LockModeType.PESSIMISTIC_WRITE,props);
		tx.commit();


this code works fine, but to test the timeout i get a manuell lock on the same row via commandline before executing the java code:
set autocommit=0;
select * ...for update;


the problem is, the javacode ignores the 3s timeout and doesn't throw a lock timeout exception but instead a PessimisticLockException after 60s. So how to get timeout to work?

meanwhile i tried to set the timeout in persistence.xml (em.getProperties shows it) but no success - the timeout is still ignored.

[Updated on: Fri, 23 July 2010 06:17]

Report message to a moderator

Re: javax.persistence.lock.timeout is beeing ignored... [message #548957 is a reply to message #548793] Fri, 23 July 2010 14:34 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1024
Registered: July 2009
Senior Member
Hello,

What database are you using, and does it support timeout options on select for update? EclipseLink's databasePlatform class is responsible for trying to interpret the database exception to determine if it was due to a timeout or another error, and I believe only the OraclePlatform class overrides the isLockTimeoutException to support throwing the LockTimeoutException.

Best Regards,
Chris
Re: javax.persistence.lock.timeout is beeing ignored... [message #549200 is a reply to message #548793] Mon, 26 July 2010 05:26 Go to previous messageGo to next message
moritz du is currently offline moritz du
Messages: 98
Registered: February 2010
Member
thx for your answer
i am using MySql. I thought the timeout setting is only on Java side: Java waits for this lock.timeout to get a lock and then throws an exception?!
And why all JPA-related books/sites describe the lock.timeout as an nearly mandatory setting in conjunction with pessimistic locking?(all describe the dfference between timeoutException and lockException as a matter of the necessary rollback level: timeout for statement rollback and lockException for transaction level rollback)

So how to implement pessimistic locking with MySql? Is it possible to timeout the operation for myself - to throw an exception after some time?
Or what is the server/data base setting that sets the 60min timeout?

EDIT: i googled around a bit and found that since innodb version 1.0.2 it is possible to set "innodb_lock_wait_timeout" per session. But how to set it via JPA? ist it possible to set it in persitence.xml?

[Updated on: Mon, 26 July 2010 06:49]

Report message to a moderator

Re: javax.persistence.lock.timeout is beeing ignored... [message #550907 is a reply to message #549200] Wed, 04 August 2010 15:32 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You would have to execute a native SQL query to set this per session, or configure a default on your database.


James : Wiki : Book : Blog : Twitter
Re: javax.persistence.lock.timeout is beeing ignored... [message #551342 is a reply to message #548793] Fri, 06 August 2010 05:52 Go to previous message
moritz du is currently offline moritz du
Messages: 98
Registered: February 2010
Member
i figured out tha i use version of innodb where this setting is only server wide settable. updating the server or setting a diiferent time out are no options - it's a production server.

i come more and more to the onclusion that combining JPA with my SQL was not a good idea. it is my very first jpa application and i stumble across Problems that all seem to be MySql related.
(see http://www.eclipse.org/forums/index.php?t=msg&th=173056& amp;start=0&S=0f713beeca8c2af948d02bf5c5620e06
and
http://www.eclipse.org/forums/index.php?t=msg&goto=55134 1&S=8dfca60dba3cd2ee86e3190c9bd25f1a)
Previous Topic:Eclipselink + c3p0
Next Topic:foreign key constraint problem
Goto Forum:
  


Current Time: Tue Sep 30 20:10:03 GMT 2014

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

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