From bd49676cb6bed320b3462d04964eaa09dbec6a54 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 28 Feb 2017 00:32:53 -0500 Subject: [PATCH] HHH-2735 - Added test cases. --- .../hibernate/test/locking/LockModeTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/locking/LockModeTest.java b/hibernate-core/src/test/java/org/hibernate/test/locking/LockModeTest.java index 940b8e9e49..c16ed0efc1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/locking/LockModeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/locking/LockModeTest.java @@ -136,6 +136,30 @@ public class LockModeTest extends BaseCoreFunctionalTestCase { } ); } + @Test + @TestForIssue(jiraKey = "HHH-2735") + public void testQueryLockModeNoneWithAlias() { + doInHibernate( this::sessionFactory, session -> { + // shouldn't throw an exception + session.createQuery( "SELECT a.value FROM A a where a.id = :id" ) + .setLockMode( "a", LockMode.NONE ) + .setParameter( "id", 1L ) + .list(); + } ); + } + + @Test + @TestForIssue(jiraKey = "HHH-2735") + public void testQueryLockModePessimisticWriteWithAlias() { + doInHibernate( this::sessionFactory, session -> { + // shouldn't throw an exception + session.createQuery( "SELECT MAX(a.id)+1 FROM A a where a.value = :value" ) + .setLockMode( "a", LockMode.PESSIMISTIC_WRITE ) + .setParameter( "value", "it" ) + .list(); + } ); + } + private void nowAttemptToUpdateRow() { // here we just need to open a new connection (database session and transaction) and make sure that // we are not allowed to acquire exclusive locks to that row and/or write to that row. That may take