Search in sources :

Example 16 with LockOptions

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();
}
Also used : LockOptions(org.hibernate.LockOptions) Session(org.hibernate.Session) Test(org.junit.Test)

Example 17 with LockOptions

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();
}
Also used : LockOptions(org.hibernate.LockOptions) Session(org.hibernate.Session) Test(org.junit.Test)

Example 18 with LockOptions

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();
}
Also used : LockOptions(org.hibernate.LockOptions) Session(org.hibernate.Session) Test(org.junit.Test)

Example 19 with LockOptions

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();
}
Also used : LockOptions(org.hibernate.LockOptions) Session(org.hibernate.Session) Test(org.junit.Test)

Example 20 with LockOptions

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();
}
Also used : LockOptions(org.hibernate.LockOptions) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

LockOptions (org.hibernate.LockOptions)64 Test (org.junit.Test)43 Session (org.hibernate.Session)23 TestForIssue (org.hibernate.testing.TestForIssue)14 PersistenceException (javax.persistence.PersistenceException)5 SQLGrammarException (org.hibernate.exception.SQLGrammarException)5 LockMode (org.hibernate.LockMode)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 RowSelection (org.hibernate.engine.spi.RowSelection)3 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)3 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)3 AfterLoadAction (org.hibernate.loader.spi.AfterLoadAction)3 Loadable (org.hibernate.persister.entity.Loadable)3 RequiresDialect (org.hibernate.testing.RequiresDialect)3 Serializable (java.io.Serializable)2 CallableStatement (java.sql.CallableStatement)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2