Skip to content

Commit 69fd7b8

Browse files
committed
HHH-19336 - Proper implementation for JPA extended locking scope
HHH-19459 - LockScope, FollowOnLocking
1 parent f3cc425 commit 69fd7b8

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public String appendLockHint(LockOptions lockOptions, String tableName) {
216216

217217
@Override
218218
public String applyLocksToSql(String sql, LockOptions lockOptions, Map<String, String[]> keyColumnNameMap) {
219-
if ( lockOptions.getLockMode() == LockMode.NONE ) {
219+
if ( lockOptions.getLockMode() == LockMode.NONE || keyColumnNameMap == null ) {
220220
return sql;
221221
}
222222

hibernate-core/src/test/java/org/hibernate/orm/test/locking/scope/BaselineTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import jakarta.persistence.LockModeType;
88
import org.hibernate.Hibernate;
99
import org.hibernate.dialect.RowLockStrategy;
10+
import org.hibernate.dialect.lock.PessimisticLockStyle;
1011
import org.hibernate.testing.jdbc.SQLStatementInspector;
1112
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1213
import org.hibernate.testing.orm.junit.DomainModel;
@@ -86,9 +87,11 @@ void testQueryJoiningTagsWithLocking(SessionFactoryScope factoryScope) {
8687
Helper.deleteFromTable( factoryScope, "book_authors", false );
8788

8889
// Whether the `book_tags` table should be locked or not depends on the capability of the db:
90+
// * if the database uses table hints, it will be locked
8991
// * if the database supports for-update-of, it will not be locked since `of` will only reference the root table (`books`)
9092
// * if the database supports for-update (no -of), it will be locked since it locks all returned rows
91-
final boolean expectingToBlockTags = session.getDialect().getWriteRowLockStrategy() == RowLockStrategy.NONE;
93+
final boolean expectingToBlockTags = session.getDialect().getWriteRowLockStrategy() == RowLockStrategy.NONE
94+
|| session.getDialect().getPessimisticLockStyle() == PessimisticLockStyle.TABLE_HINT;
9295
Helper.deleteFromTable( factoryScope, "book_tags", expectingToBlockTags );
9396

9497
// The `books` table should be locked.

hibernate-core/src/test/java/org/hibernate/orm/test/locking/scope/Helper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ else if ( rowLockStrategy == RowLockStrategy.TABLE ) {
138138
// Transact SQL (mssql, sybase) "table hint"-style locking
139139
final LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_WRITE );
140140
for ( Table table : tablesFetched ) {
141-
final String booksTableReference = dialect.appendLockHint( lockOptions, table.getTableName() );
141+
final String booksTableReference = dialect.appendLockHint( lockOptions, table.getTableAlias() );
142142
assertThat( sql ).contains( booksTableReference );
143143
}
144144
}

0 commit comments

Comments
 (0)