[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-3961) SQLServerDialect, support nowait in LockMode.UPGRADE_NOWAIT

Guenther Demetz (JIRA) noreply at atlassian.com
Thu Apr 19 04:55:48 EDT 2012


     [ https://hibernate.onjira.com/browse/HHH-3961?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Guenther Demetz updated HHH-3961:
---------------------------------

    Attachment: HHH-3961MatrixTestcase.jar

Attached matrix testcase 

> SQLServerDialect, support nowait in LockMode.UPGRADE_NOWAIT 
> ------------------------------------------------------------
>
>                 Key: HHH-3961
>                 URL: https://hibernate.onjira.com/browse/HHH-3961
>             Project: Hibernate ORM
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.3.1
>         Environment: 3.3.1 GA , SQLServer2008
>            Reporter: Guenther Demetz
>            Assignee: Strong Liu
>            Priority: Trivial
>         Attachments: HHH-3961MatrixTestcase.jar
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The method SQLServerDialect#appendLockHint currently ignores the LockMode.UPGRADE_NOWAIT returning the same string as for 
> LockMode.UPGRADE.
> public String appendLockHint(LockMode mode, String tableName) {
> 	   if ( mode.greaterThan( LockMode.READ ) ) {
> 			// does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)";
> 			return tableName + " with (updlock, rowlock)";
> 		}
> 		else {
> 			return tableName;
> 		}
> 	}
> As SQLServer supports the nowait option I propose the following improvement:
> public String appendLockHint(LockMode mode, String tableName) {
> 	    if ( mode == LockMode.UPGRADE_NOWAIT) {
> 	        return tableName + " with (updlock, rowlock, nowait)";
> 	    }
> 	    else if ( mode.greaterThan( LockMode.READ ) ) {
> 			// does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)";
> 			return tableName + " with (updlock, rowlock)";
> 		}
> 		else {
> 			return tableName;
> 		}
> 	}
> A test gave me a correct behaviour: if the concerning row is already locked, 
> then after Lock request time out period exceeded following exception is thrown:
> org.hibernate.exception.SQLGrammarException: could not lock: [persistent.jpa.AssociationsClassPeer#1]
> 	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
> 	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
> 	at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:115)
> 	at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1361)
> 	at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:108)
> 	at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:87)
> 	at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:611)
> 	at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:603)
> 	...
> Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Lock request time out period exceeded.
> 	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
> 	at com.microsoft.sqlserver.jdbc.SQLServerResultSet$FetchBuffer.nextRow(SQLServerResultSet.java:4700)
> 	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.fetchBufferNext(SQLServerResultSet.java:1683)
> 	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.next(SQLServerResultSet.java:956)
> 	at com.p6spy.engine.spy.P6ResultSet.next(P6ResultSet.java:156)
> 	at com.p6spy.engine.logging.P6LogResultSet.next(P6LogResultSet.java:124)
> 	at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:2859)
> 	at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:97)
>         ... 24 more

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list