Skip to content

Commit e242509

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

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

hibernate-core/src/main/java/org/hibernate/LockOptions.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,14 @@ public Boolean getFollowOnLocking() {
417417
*/
418418
@Deprecated(since = "7.1")
419419
public LockOptions setFollowOnLocking(Boolean followOnLocking) {
420-
if ( followOnLocking != null ) {
421-
this.followOnStrategy = followOnLocking == Boolean.FALSE
422-
? Locking.FollowOn.DISALLOW
423-
: Locking.FollowOn.FORCE;
420+
if ( followOnLocking == null ) {
421+
this.followOnStrategy = Locking.FollowOn.ALLOW;
422+
}
423+
else {
424+
this.followOnStrategy = followOnLocking
425+
? Locking.FollowOn.FORCE
426+
// todo : DISALLOW or IGNORE?
427+
: Locking.FollowOn.IGNORE;
424428
}
425429
return this;
426430
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import jakarta.persistence.LockModeType;
88
import org.hibernate.Hibernate;
9+
import org.hibernate.dialect.HSQLDialect;
910
import org.hibernate.dialect.RowLockStrategy;
1011
import org.hibernate.dialect.lock.PessimisticLockStyle;
1112
import org.hibernate.testing.jdbc.SQLStatementInspector;
@@ -15,6 +16,7 @@
1516
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1617
import org.hibernate.testing.orm.junit.SessionFactory;
1718
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.hibernate.testing.orm.junit.SkipForDialect;
1820
import org.hibernate.testing.orm.transaction.TransactionUtil;
1921
import org.junit.jupiter.api.AfterEach;
2022
import org.junit.jupiter.api.BeforeEach;
@@ -69,6 +71,7 @@ void testFindWithLocking(SessionFactoryScope factoryScope) {
6971
}
7072

7173
@Test
74+
@SkipForDialect(dialectClass = HSQLDialect.class, reason = "See https://sourceforge.net/p/hsqldb/bugs/1734/")
7275
void testQueryJoiningTagsWithLocking(SessionFactoryScope factoryScope) {
7376
// NOTE: roughly the same expectations as #testFindWithExtendedLocking,
7477
// but here the `book_tags` table should also get locked

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import jakarta.persistence.PessimisticLockScope;
99
import org.hibernate.Hibernate;
1010
import org.hibernate.Locking;
11+
import org.hibernate.dialect.HSQLDialect;
1112
import org.hibernate.testing.jdbc.SQLStatementInspector;
1213
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1314
import org.hibernate.testing.orm.junit.DomainModel;
1415
import org.hibernate.testing.orm.junit.Jira;
1516
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1617
import org.hibernate.testing.orm.junit.SessionFactory;
1718
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.hibernate.testing.orm.junit.SkipForDialect;
1820
import org.hibernate.testing.orm.transaction.TransactionUtil;
1921
import org.junit.jupiter.api.AfterEach;
2022
import org.junit.jupiter.api.BeforeEach;
@@ -76,6 +78,7 @@ void testFindWithExtendedLocking(SessionFactoryScope factoryScope) {
7678
}
7779

7880
@Test
81+
@SkipForDialect(dialectClass = HSQLDialect.class, reason = "See https://sourceforge.net/p/hsqldb/bugs/1734/")
7982
void testQueryJoiningTagsWithExtendedLocking(SessionFactoryScope factoryScope) {
8083
// NOTE: roughly the same expectations as #testFindWithExtendedLocking,
8184
// but here the `book_tags` table should also get locked

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import jakarta.persistence.LockModeType;
88
import org.hibernate.Hibernate;
99
import org.hibernate.Locking;
10+
import org.hibernate.dialect.HSQLDialect;
1011
import org.hibernate.testing.jdbc.SQLStatementInspector;
1112
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1213
import org.hibernate.testing.orm.junit.DomainModel;
1314
import org.hibernate.testing.orm.junit.Jira;
1415
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1516
import org.hibernate.testing.orm.junit.SessionFactory;
1617
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18+
import org.hibernate.testing.orm.junit.SkipForDialect;
1719
import org.hibernate.testing.orm.transaction.TransactionUtil;
1820
import org.junit.jupiter.api.AfterEach;
1921
import org.junit.jupiter.api.BeforeEach;
@@ -69,6 +71,7 @@ void testFindWithFetchLocking(SessionFactoryScope factoryScope) {
6971
}
7072

7173
@Test
74+
@SkipForDialect(dialectClass = HSQLDialect.class, reason = "See https://sourceforge.net/p/hsqldb/bugs/1734/")
7275
void testQueryJoiningTagsWithFetchLocking(SessionFactoryScope factoryScope) {
7376
final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector();
7477

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ else if ( rowLockStrategy == RowLockStrategy.COLUMN_NAME ) {
136136
aliases = buffer.toString();
137137
}
138138
else {
139+
assert rowLockStrategy == RowLockStrategy.COLUMN;
139140
final StringBuilder buffer = new StringBuilder();
140141
boolean firstPass = true;
141142
for ( Table table : tablesFetched ) {

0 commit comments

Comments
 (0)