-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: LockMode.UPGRADE seems broken for Derby
PostPosted: Thu Jun 21, 2007 11:00 pm 
Newbie

Joined: Thu Jun 21, 2007 10:38 pm
Posts: 3
Location: Seattle, WA
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 12:13 pm 
Newbie

Joined: Thu Jun 21, 2007 10:38 pm
Posts: 3
Location: Seattle, WA
Could anyone from the Hibernate team confirm that this should be filed with JIRA?

Thanks!


Top
 Profile  
 
 Post subject: Derby locking
PostPosted: Tue Jul 29, 2008 2:11 pm 
Newbie

Joined: Tue Jun 03, 2008 9:12 am
Posts: 1
Hi,

I'm not from the Hibernate team but I can confirm I was having the same problem.

A workaround is just to subclass DerbyDialect and override getForUpdateString as in:

public class DerbyDialect extends org.hibernate.dialect.DerbyDialect {

/**
* Uses "for update" rather than "for read only" as per Derby docs
*
* @see org.hibernate.dialect.DB2Dialect#getForUpdateString()
*/
@Override
public String getForUpdateString() {
return " for update with rs";
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.