javax.persistence.lock.timeout is beeing ignored... [message #548793] |
Fri, 23 July 2010 05:45 |
moritz du Messages: 102 Registered: February 2010 |
Senior 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 #549200 is a reply to message #548793] |
Mon, 26 July 2010 05:26 |
moritz du Messages: 102 Registered: February 2010 |
Senior 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02265 seconds