|
9 | 9 | import org.hibernate.LockMode;
|
10 | 10 | import org.hibernate.LockOptions;
|
11 | 11 | import org.hibernate.Locking;
|
| 12 | +import org.hibernate.dialect.Dialect; |
12 | 13 | import org.hibernate.dialect.H2Dialect;
|
13 | 14 | import org.hibernate.dialect.HSQLDialect;
|
| 15 | +import org.hibernate.dialect.RowLockStrategy; |
14 | 16 | import org.hibernate.dialect.lock.PessimisticLockStyle;
|
15 | 17 | import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
|
16 | 18 | import org.hibernate.testing.jdbc.SQLStatementInspector;
|
@@ -236,11 +238,35 @@ void testEagerFind(SessionFactoryScope factoryScope) {
|
236 | 238 | assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 );
|
237 | 239 | Helper.checkSql( sqlCollector.getSqlQueries().get( 0 ), session.getDialect(), REPORTS );
|
238 | 240 | 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() ) ); |
241 | 243 | } );
|
242 | 244 | }
|
243 | 245 |
|
| 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 | + |
244 | 270 | @Test
|
245 | 271 | @SkipForDialect(dialectClass = HSQLDialect.class, reason = "See https://sourceforge.net/p/hsqldb/bugs/1734/")
|
246 | 272 | @SkipForDialect(dialectClass = H2Dialect.class, reason = "H2 seems to not extend locks across joins")
|
|
0 commit comments