Skip to content

Commit f4f5264

Browse files
runeksbrmeyer
authored andcommitted
HHH-8756 test cases for non select queries when lock mode is set to NONE
1 parent a32b5df commit f4f5264

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/QueryLockingTest.java

100644100755
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import javax.persistence.Query;
3333
import javax.persistence.Table;
3434

35+
import org.hibernate.testing.TestForIssue;
3536
import org.junit.Test;
3637

3738
import org.hibernate.LockMode;
@@ -89,6 +90,39 @@ public void testOverallLockMode() {
8990
em.close();
9091
}
9192

93+
@Test
94+
@TestForIssue( jiraKey = "HHH-8756" )
95+
public void testLockModeSetToNoneForNonSelectQueryShouldBeAllowed() {
96+
EntityManager em = getOrCreateEntityManager();
97+
em.getTransaction().begin();
98+
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
99+
100+
org.hibernate.internal.QueryImpl hqlQuery = (org.hibernate.internal.QueryImpl) jpaQuery.getHibernateQuery();
101+
assertEquals( LockMode.NONE, hqlQuery.getLockOptions().getLockMode() );
102+
103+
jpaQuery.setLockMode( LockModeType.NONE );
104+
105+
em.getTransaction().commit();
106+
em.close();
107+
}
108+
109+
@Test( expected = IllegalStateException.class )
110+
@TestForIssue( jiraKey = "HHH-8756" )
111+
public void testLockModeSetToValueOtherThanNoneForNonSelectQueryIsNotAllowed() {
112+
EntityManager em = getOrCreateEntityManager();
113+
em.getTransaction().begin();
114+
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
115+
116+
org.hibernate.internal.QueryImpl hqlQuery = (org.hibernate.internal.QueryImpl) jpaQuery.getHibernateQuery();
117+
assertEquals( LockMode.NONE, hqlQuery.getLockOptions().getLockMode() );
118+
119+
// Throws IllegalStateException
120+
jpaQuery.setLockMode( LockModeType.PESSIMISTIC_WRITE );
121+
122+
em.getTransaction().commit();
123+
em.close();
124+
}
125+
92126
@Test
93127
public void testNativeSql() {
94128
EntityManager em = getOrCreateEntityManager();

0 commit comments

Comments
 (0)