HHH-8756 test cases for non select queries when lock mode is set to NONE
This commit is contained in:
parent
a32b5dfa74
commit
f4f5264cd2
34
hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/QueryLockingTest.java
Normal file → Executable file
34
hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/QueryLockingTest.java
Normal file → Executable file
|
@ -32,6 +32,7 @@ import javax.persistence.LockModeType;
|
|||
import javax.persistence.Query;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
|
@ -89,6 +90,39 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
|||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-8756" )
|
||||
public void testLockModeSetToNoneForNonSelectQueryShouldBeAllowed() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
|
||||
|
||||
org.hibernate.internal.QueryImpl hqlQuery = (org.hibernate.internal.QueryImpl) jpaQuery.getHibernateQuery();
|
||||
assertEquals( LockMode.NONE, hqlQuery.getLockOptions().getLockMode() );
|
||||
|
||||
jpaQuery.setLockMode( LockModeType.NONE );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Test( expected = IllegalStateException.class )
|
||||
@TestForIssue( jiraKey = "HHH-8756" )
|
||||
public void testLockModeSetToValueOtherThanNoneForNonSelectQueryIsNotAllowed() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
|
||||
|
||||
org.hibernate.internal.QueryImpl hqlQuery = (org.hibernate.internal.QueryImpl) jpaQuery.getHibernateQuery();
|
||||
assertEquals( LockMode.NONE, hqlQuery.getLockOptions().getLockMode() );
|
||||
|
||||
// Throws IllegalStateException
|
||||
jpaQuery.setLockMode( LockModeType.PESSIMISTIC_WRITE );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeSql() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
|
Loading…
Reference in New Issue