[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5275) Criteria.setLockMode does not work correctly
Jakob Braeuchi (JIRA)
noreply at atlassian.com
Thu Nov 11 02:27:13 EST 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39082#action_39082 ]
Jakob Braeuchi commented on HHH-5275:
-------------------------------------
there also is a difference in the generated sql:
query.*setLockMode*("cat", LockMode.UPGRADE);
generates "select ... *for update of this_.CAT_ID*" with hibernate 3.3.2
query.*setLockOptions*(new LockOptions(LockMode.UPGRADE))
generates "select ... *for update*" with hibernate 3.5.6
according to our oracle-specialist this makes no difference because both ways lock the whole row.
to make setLockMode() work like setLockOptions() the method MyDialect#getForUpdateString() could look like this:
{noformat}
public String getForUpdateString(String aliases, LockOptions lockOptions)
{
LockMode lockMode = lockOptions.getLockMode();
Iterator<Map.Entry<String, LockMode>> iter = lockOptions.getAliasLockIterator();
while(iter.hasNext())
{
// get highest LockMode
Map.Entry<String, LockMode>entry = iter.next();
LockMode lm = entry.getValue();
if (lm.greaterThan(lockMode))
{
lockMode = lm;
}
}
lockOptions.setLockMode(lockMode);
return super.getForUpdateString(aliases, lockOptions);
}
{noformat}
actually the same logic could be applied to org.hibernate.LockOptions#setAliasSpecificLockMode():
{noformat}
public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
aliasSpecificLockModes.put( alias, lockMode );
// set higher LockMode
if (this.lockMode.lessThan(lockMode))
{
this.lockMode = lockMode;
}
return this;
}
{noformat}
this worked for the queries i was testing. but i'm not sure if this is the way LockOptions should work.
> Criteria.setLockMode does not work correctly
> --------------------------------------------
>
> Key: HHH-5275
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5275
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.5.2, 3.5.3
> Environment: Hibernate 3.5.2, Oracle 10 (using org.hibernate.dialect.Oracle10gDialect
> Reporter: Björn Moritz
> Priority: Minor
> Fix For: 3.6.1
>
> Attachments: My_Oracle10Dialect.java, My_Oracle10Dialect.java, TestCase.zip
>
>
> The LockMode set via Criteria.setLockMode does not generate a ' for update' SQL statement. In the org.hibernate.dialect.Dialect class only the LockOptions are used for determining a possible addition to the SQL statement if using pessimistic locking. This behaviour is different from Hibernate 3.1.3.
> In the supplied TestCase two threads are reading the same database record; one of those threads should use pessimistic locking thereby blocking the other thread. But both threads can read the database record causing the test to fail.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list