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

Guenther Demetz (JIRA) noreply at atlassian.com
Mon Jun 15 07:58:33 EDT 2009


SQLServerDialect, support nowait in LockMode.UPGRADE_NOWAIT 
------------------------------------------------------------

                 Key: HHH-3961
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3961
             Project: Hibernate Core
          Issue Type: Improvement
          Components: core
    Affects Versions: 3.3.1
         Environment: 3.3.1 GA , SQLServer2008
            Reporter: Guenther Demetz
            Priority: Trivial


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