use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithCountDistinctThenFollowOnLocking.
@Test
public void testPessimisticLockWithCountDistinctThenFollowOnLocking() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
List<Product> products = session.createQuery("select p from Product p where ( select count(distinct p1.id) from Product p1 ) > 0 ", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(false)).getResultList();
assertEquals(50, products.size());
assertEquals(1, sqlStatementInterceptor.getSqlQueries().size());
session.getTransaction().commit();
session.close();
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithMaxResultsAndOrderByWhileExplicitlyEnablingFollowOnLockingThenFollowOnLocking.
@Test
public void testPessimisticLockWithMaxResultsAndOrderByWhileExplicitlyEnablingFollowOnLockingThenFollowOnLocking() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
List<Product> products = session.createQuery("select p from Product p order by p.id", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(true)).setMaxResults(10).getResultList();
assertEquals(10, products.size());
assertEquals(11, sqlStatementInterceptor.getSqlQueries().size());
session.getTransaction().commit();
session.close();
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithDistinctThenFollowOnLocking.
@Test
public void testPessimisticLockWithDistinctThenFollowOnLocking() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
List<Product> products = session.createQuery("select distinct p from Product p", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE)).getResultList();
assertEquals(50, products.size());
assertEquals(51, sqlStatementInterceptor.getSqlQueries().size());
session.getTransaction().commit();
session.close();
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithMaxResultsAndOrderByWhileExplicitlyDisablingFollowOnLockingThenFails.
@Test
public void testPessimisticLockWithMaxResultsAndOrderByWhileExplicitlyDisablingFollowOnLockingThenFails() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
try {
List<Product> products = session.createQuery("select p from Product p order by p.id", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(false)).setMaxResults(10).getResultList();
fail("Should throw exception since Oracle does not support ORDER BY if follow on locking is disabled");
} catch (PersistenceException expected) {
assertEquals(SQLGrammarException.class, expected.getCause().getClass());
}
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class SQLServer2005LockHintsTest method lockOptions.
@Override
protected LockOptions lockOptions(String aliasToLock) {
LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.NO_WAIT);
lockOptions.setAliasSpecificLockMode(aliasToLock, LockMode.PESSIMISTIC_WRITE);
return lockOptions;
}
Aggregations