HHH-8756 cleanup
This commit is contained in:
parent
f4f5264cd2
commit
a76a7e9b42
|
@ -23,8 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.test.lock;
|
package org.hibernate.jpa.test.lock;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -32,22 +40,14 @@ import javax.persistence.LockModeType;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
|
import org.hibernate.internal.SessionImpl;
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.QueryHints;
|
import org.hibernate.jpa.QueryHints;
|
||||||
import org.hibernate.jpa.internal.QueryImpl;
|
import org.hibernate.jpa.internal.QueryImpl;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.internal.SessionImpl;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -92,7 +92,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-8756" )
|
@TestForIssue( jiraKey = "HHH-8756" )
|
||||||
public void testLockModeSetToNoneForNonSelectQueryShouldBeAllowed() {
|
public void testNoneLockModeForNonSelectQueryAllowed() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
|
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
|
||||||
|
@ -103,25 +103,28 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
jpaQuery.setLockMode( LockModeType.NONE );
|
jpaQuery.setLockMode( LockModeType.NONE );
|
||||||
|
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.clear();
|
||||||
}
|
|
||||||
|
|
||||||
@Test( expected = IllegalStateException.class )
|
// ensure other modes still throw the exception
|
||||||
@TestForIssue( jiraKey = "HHH-8756" )
|
|
||||||
public void testLockModeSetToValueOtherThanNoneForNonSelectQueryIsNotAllowed() {
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
QueryImpl jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
|
jpaQuery = em.createQuery( "delete from Lockable l" ).unwrap( QueryImpl.class );
|
||||||
|
|
||||||
org.hibernate.internal.QueryImpl hqlQuery = (org.hibernate.internal.QueryImpl) jpaQuery.getHibernateQuery();
|
hqlQuery = (org.hibernate.internal.QueryImpl) jpaQuery.getHibernateQuery();
|
||||||
assertEquals( LockMode.NONE, hqlQuery.getLockOptions().getLockMode() );
|
assertEquals( LockMode.NONE, hqlQuery.getLockOptions().getLockMode() );
|
||||||
|
|
||||||
|
try {
|
||||||
// Throws IllegalStateException
|
// Throws IllegalStateException
|
||||||
jpaQuery.setLockMode( LockModeType.PESSIMISTIC_WRITE );
|
jpaQuery.setLockMode( LockModeType.PESSIMISTIC_WRITE );
|
||||||
|
fail( "IllegalStateException should have been thrown." );
|
||||||
em.getTransaction().commit();
|
}
|
||||||
|
catch (IllegalStateException e) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNativeSql() {
|
public void testNativeSql() {
|
||||||
|
|
Loading…
Reference in New Issue