[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-1889) LockMode.UPGRADE does not work for get(), load() and refresh() on SQL Server

Steve Finch (JIRA) noreply at atlassian.com
Mon Nov 20 15:24:05 EST 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1889?page=all ]

Steve Finch updated HHH-1889:
-----------------------------

    Attachment: SQLServerDialect.applyLocks.patch

I'm attaching a second patch that fixes the use of inline lock hints for HQL and Criteria queries.  I thought it would be harder than it was, but I've tested it and it works as expected.

My methodology:
1) Locate all the places where ForUpdateFragment is appended to the existing SQL (QueryTranslatorImpl, QueryLoader, and CriteriaLoader);
2) Refactor the code to move this behavior to the Dialect class;
3) Override the new method in the SQLServerDialect class;
4) Create a new class InlineUpdateLockModification which replaces the aliases in the FROM clause with the appropriate update lock hint, if necessary.

I'm not exactly happy with the solution, as it causes the query to be reprocessed each time lock hints occur.  However, it seemed a lesser risk than playing with the HQLQueryPlanKey class and adding some metadata about what locks would be needed.  My fix could be sped up if there were bookmarks telling where each alias existed in the existing query; with that information a search would not be necessary and the resulting code would be safer.


> LockMode.UPGRADE does not work for get(), load() and refresh() on SQL Server
> ----------------------------------------------------------------------------
>
>          Key: HHH-1889
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1889
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.2.0.cr2, 3.2.0.cr3
>  Environment: Windows XP, Hibernate 3.2.cr3
>     Reporter: Matthias Germann
>     Priority: Critical
>  Attachments: AbstractEntityJoinWalker.java.patch, SQLServerDialect.applyLocks.patch
>
>
> Passing a LockMode parameter to the get(), load() or refresh() method of the Session class has no effect on MS SQL Server.
> The statement 
> session.load(ProcessInstance.class, 33l, LockMode.UPGRADE)
> produces this SQL Statement with the SQLServerDialect:
> select
>         processins0_.ID_ as ID1_20_0_,
>         processins0_.VERSION_ as VERSION2_20_0_,
>         processins0_.START_ as START3_20_0_,
>         processins0_.END_ as END4_20_0_,
>         processins0_.ISSUSPENDED_ as ISSUSPEN5_20_0_,
>         processins0_.PROCESSDEFINITION_ as PROCESSD6_20_0_,
>         processins0_.ROOTTOKEN_ as ROOTTOKEN7_20_0_,
>         processins0_.SUPERPROCESSTOKEN_ as SUPERPRO8_20_0_ 
>     from
>         JBPM_PROCESSINSTANCE processins0_ 
>     where
>         processins0_.ID_=?
> This Statement does not contain the requested locking hint. The FROM claus should look like this:
> from JBPM_PROCESSINSTANCE processins0_ with (updlock, rowlock)
> The OracleDialect produces a correct statement with a FOR UPDATE clause
>     select
>         processins0_.ID_ as ID1_20_0_,
>         processins0_.VERSION_ as VERSION2_20_0_,
>         processins0_.START_ as START3_20_0_,
>         processins0_.END_ as END4_20_0_,
>         processins0_.ISSUSPENDED_ as ISSUSPEN5_20_0_,
>         processins0_.PROCESSDEFINITION_ as PROCESSD6_20_0_,
>         processins0_.ROOTTOKEN_ as ROOTTOKEN7_20_0_,
>         processins0_.SUPERPROCESSTOKEN_ as SUPERPRO8_20_0_ 
>     from
>         JBPM_PROCESSINSTANCE processins0_ 
>     where
>         processins0_.ID_=? for update
> The lock() method works correctly. 
> IMHO, the problem is that only the SimpleSelect class uses the appendLockHint() method of the Dialect class. The Select class does not seam to use the appendLockHint() method.

-- 
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