mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-20 01:55:02 +00:00
HHH-12880 LockModeTest hangs indefinitely with Sybase due to HHH-12847
This commit is contained in:
parent
c108f48674
commit
07e21cf66e
@ -16,6 +16,7 @@
|
|||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||||
|
import org.hibernate.dialect.SybaseDialect;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
import org.hibernate.testing.SkipForDialect;
|
||||||
@ -242,12 +243,19 @@ private void nowAttemptToUpdateRow() {
|
|||||||
doInHibernate( this::sessionFactory, _session -> {
|
doInHibernate( this::sessionFactory, _session -> {
|
||||||
TransactionUtil.setJdbcTimeout( _session );
|
TransactionUtil.setJdbcTimeout( _session );
|
||||||
try {
|
try {
|
||||||
// load with write lock to deal with databases that block (wait indefinitely) direct attempts
|
// We used to load with write lock here to deal with databases that block (wait indefinitely)
|
||||||
// to write a locked row
|
// direct attempts to write a locked row.
|
||||||
|
// At some point, due to a bug, the lock mode was lost when applied via lock options, leading
|
||||||
|
// this code to not apply the pessimistic write lock.
|
||||||
|
// See HHH-12847 + https://github.com/hibernate/hibernate-orm/commit/719e5d0c12a6ef709bee907b8b651d27b8b08a6a.
|
||||||
|
// At least Sybase waits indefinitely when really applying a PESSIMISTIC_WRITE lock here (and
|
||||||
|
// the NO_WAIT part is not applied by the Sybase dialect so it doesn't help).
|
||||||
|
// For now going back to LockMode.NONE as it's the lock mode that has been applied for quite
|
||||||
|
// some time and it seems our supported databases don't have a problem with it.
|
||||||
A it = _session.get(
|
A it = _session.get(
|
||||||
A.class,
|
A.class,
|
||||||
id,
|
id,
|
||||||
new LockOptions( LockMode.PESSIMISTIC_WRITE ).setTimeOut( LockOptions.NO_WAIT )
|
new LockOptions( LockMode.NONE ).setTimeOut( LockOptions.NO_WAIT )
|
||||||
);
|
);
|
||||||
_session.createNativeQuery( updateStatement() )
|
_session.createNativeQuery( updateStatement() )
|
||||||
.setParameter( "value", "changed" )
|
.setParameter( "value", "changed" )
|
||||||
@ -272,7 +280,8 @@ private void nowAttemptToUpdateRow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String updateStatement() {
|
protected String updateStatement() {
|
||||||
if( SQLServerDialect.class.isAssignableFrom( DIALECT.getClass() ) ) {
|
if ( SQLServerDialect.class.isAssignableFrom( DIALECT.getClass() )
|
||||||
|
|| SybaseDialect.class.isAssignableFrom( DIALECT.getClass() ) ) {
|
||||||
return "UPDATE T_LOCK_A WITH(NOWAIT) SET a_value = :value where id = :id";
|
return "UPDATE T_LOCK_A WITH(NOWAIT) SET a_value = :value where id = :id";
|
||||||
}
|
}
|
||||||
return "UPDATE T_LOCK_A SET a_value = :value where id = :id";
|
return "UPDATE T_LOCK_A SET a_value = :value where id = :id";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user