use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithGroupByWhileExplicitlyEnablingFollowOnLockingThenFollowOnLocking.
@Test
public void testPessimisticLockWithGroupByWhileExplicitlyEnablingFollowOnLockingThenFollowOnLocking() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
List<Object[]> products = session.createQuery("select count(p), p " + "from Product p " + "group by p.id, p.name ").setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(true)).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 testPessimisticLockWithFirstResultsThenFollowOnLocking.
@Test
public void testPessimisticLockWithFirstResultsThenFollowOnLocking() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
List<Product> products = session.createQuery("select p from Product p", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE)).setFirstResult(40).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 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();
}
Aggregations