HHH-8756 test cases for non select queries when lock mode is set to NONE

This commit is contained in:
Rune Steinseth 2014-01-03 10:12:01 +01:00 committed by Brett Meyer
parent a32b5dfa74
commit f4f5264cd2
1 changed files with 34 additions and 0 deletions

View 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();