Skip to content

Commit 2a852c6

Browse files
committed
HHH-19336 - Proper implementation for JPA extended locking scope
HHH-19459 - LockScope, FollowOnLocking HHH-19501 - Session#lock w/ pessimistic locks for scopes HHH-19502 - Disallow SKIP_LOCKED with Session#lock HHH-19503 - Track a Dialect's level of support for locking joined tables
1 parent 96960bf commit 2a852c6

File tree

1 file changed

+28
-2
lines changed
  • hibernate-core/src/test/java/org/hibernate/orm/test/locking/options

1 file changed

+28
-2
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/locking/options/ScopeTests.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import org.hibernate.LockMode;
1010
import org.hibernate.LockOptions;
1111
import org.hibernate.Locking;
12+
import org.hibernate.dialect.Dialect;
1213
import org.hibernate.dialect.H2Dialect;
1314
import org.hibernate.dialect.HSQLDialect;
15+
import org.hibernate.dialect.RowLockStrategy;
1416
import org.hibernate.dialect.lock.PessimisticLockStyle;
1517
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
1618
import org.hibernate.testing.jdbc.SQLStatementInspector;
@@ -236,11 +238,35 @@ void testEagerFind(SessionFactoryScope factoryScope) {
236238
assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 );
237239
Helper.checkSql( sqlCollector.getSqlQueries().get( 0 ), session.getDialect(), REPORTS );
238240
TransactionUtil.deleteFromTable( factoryScope, REPORTS.getTableName(), true );
239-
TransactionUtil.deleteFromTable( factoryScope, PERSONS.getTableName(), session.getDialect().getOuterJoinLockingLevel() == OuterJoinLockingLevel.FULL );
240-
TransactionUtil.deleteFromTable( factoryScope, REPORT_LABELS.getTableName(), session.getDialect().getOuterJoinLockingLevel() == OuterJoinLockingLevel.FULL );
241+
TransactionUtil.deleteFromTable( factoryScope, PERSONS.getTableName(), willAggressivelyLockJoinedTables( session.getDialect() ) );
242+
TransactionUtil.deleteFromTable( factoryScope, REPORT_LABELS.getTableName(), willAggressivelyLockJoinedTables( session.getDialect() ) );
241243
} );
242244
}
243245

246+
private boolean willAggressivelyLockJoinedTables(Dialect dialect) {
247+
// true when we have something like:
248+
// select ...
249+
// from books b
250+
// join persons p on ...
251+
// for update
252+
// and the database extends for-update to the joins
253+
//
254+
// todo : this is something we should consider and disallow the situation
255+
256+
final OuterJoinLockingLevel outerJoinLockingLevel = dialect.getOuterJoinLockingLevel();
257+
if ( outerJoinLockingLevel == OuterJoinLockingLevel.FULL ) {
258+
// there will be a join with some form of locking
259+
final PessimisticLockStyle pessimisticLockStyle = dialect.getPessimisticLockStyle();
260+
if ( pessimisticLockStyle == PessimisticLockStyle.CLAUSE ) {
261+
final RowLockStrategy rowLockStrategy = dialect.getWriteRowLockStrategy();
262+
if ( rowLockStrategy == RowLockStrategy.NONE ) {
263+
return true;
264+
}
265+
}
266+
}
267+
return false;
268+
}
269+
244270
@Test
245271
@SkipForDialect(dialectClass = HSQLDialect.class, reason = "See https://sourceforge.net/p/hsqldb/bugs/1734/")
246272
@SkipForDialect(dialectClass = H2Dialect.class, reason = "H2 seems to not extend locks across joins")

0 commit comments

Comments
 (0)