I've been working with using pessimistic locking in Derby, and I've observed that it doesn't apply the correct SELECT...FOR UPDATE syntax according to the Derby reference documents[1]. As a result, I'm getting StaleStateExceptions whenever multiple transactions attempt to modify the same row. I've identified that the DerbyDialect of the current codebase[2] doesn't override the getForUpdateString method, which means that it uses the one in the DB2Dialect[3]. Unfortunately, this method doesn't have the correct Derby syntax.
[1]
http://db.apache.org/derby/docs/10.2/re ... 31783.html
[2]
http://anonsvn.jboss.org/repos/hibernat ... alect.java
[3]
http://anonsvn.jboss.org/repos/hibernat ... alect.java
Hibernate version: 3.2.4.sp1
Name and version of the database you are using: Derby v10.2.2.0
Code between sessionFactory.openSession() and session.close():
Code:
Query query = this.getSession().createQuery(
"from ShoppingBag s where s.phoneDigits = :p and s.client.name = :c");
query.setString("p", phoneDigits);
query.setString("c", clientName);
query.setLockMode("s", LockMode.UPGRADE);
List<ShoppingBag> results = (List<ShoppingBag>) query.list();
The generated SQL (show_sql=true):Code:
select
shoppingba0_.SHOPPING_BAG_ID as SHOPPING1_1_,
shoppingba0_.PHONE_DIGITS as PHONE2_1_,
shoppingba0_.CLIENT_ID as CLIENT3_1_,
shoppingba0_.PIN as PIN1_
from
MSB_SHOPPING_BAGS shoppingba0_,
MSB_CLIENTS client1_
where
shoppingba0_.CLIENT_ID=client1_.CLIENT_ID and
shoppingba0_.PHONE_DIGITS=? and
client1_.NAME=?
for read only with rs
According to the Derby docs, this last bit should just be "for update". Could someone verify that I'm not missing something, and let me know whether this should be filed in JIRA?
Thanks!
Andrew Miner