use of javax.persistence.PersistenceException in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithUnionWhileExplicitlyDisablingFollowOnLockingThenFails.
@Test
public void testPessimisticLockWithUnionWhileExplicitlyDisablingFollowOnLockingThenFails() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
try {
List<Vehicle> vehicles = session.createQuery("select v from Vehicle v").setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(false)).getResultList();
fail("Should throw exception since Oracle does not support UNION if follow on locking is disabled");
} catch (PersistenceException expected) {
assertEquals(SQLGrammarException.class, expected.getCause().getClass());
}
}
use of javax.persistence.PersistenceException in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithFirstResultsWhileExplicitlyDisablingFollowOnLockingThenFails.
@Test
public void testPessimisticLockWithFirstResultsWhileExplicitlyDisablingFollowOnLockingThenFails() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
try {
List<Product> products = session.createQuery("select p from Product p", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(false)).setFirstResult(40).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 javax.persistence.PersistenceException in project hibernate-orm by hibernate.
the class OracleFollowOnLockingTest method testPessimisticLockWithDistinctWhileExplicitlyDisablingFollowOnLockingThenFails.
@Test
public void testPessimisticLockWithDistinctWhileExplicitlyDisablingFollowOnLockingThenFails() {
final Session session = openSession();
session.beginTransaction();
sqlStatementInterceptor.getSqlQueries().clear();
try {
List<Product> products = session.createQuery("select distinct p from Product p where p.id > 40", Product.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setFollowOnLocking(false)).getResultList();
fail("Should throw exception since Oracle does not support DISTINCT if follow on locking is disabled");
} catch (PersistenceException expected) {
assertEquals(SQLGrammarException.class, expected.getCause().getClass());
}
}
use of javax.persistence.PersistenceException in project hibernate-orm by hibernate.
the class ImmutableTest method testImmutableCollectionWithMerge.
@Test
public void testImmutableCollectionWithMerge() {
clearCounts();
Contract c = new Contract(null, "gavin", "phone");
ContractVariation cv1 = new ContractVariation(1, c);
cv1.setText("expensive");
ContractVariation cv2 = new ContractVariation(2, c);
cv2.setText("more expensive");
Session s = openSession();
Transaction t = s.beginTransaction();
s.persist(c);
t.commit();
s.close();
assertInsertCount(3);
assertUpdateCount(0);
clearCounts();
s = openSession();
t = s.beginTransaction();
c.getVariations().add(new ContractVariation(3, c));
s.merge(c);
try {
t.commit();
fail("should have failed because an immutable collection was changed");
} catch (PersistenceException ex) {
// expected
t.rollback();
} finally {
s.close();
}
s = openSession();
t = s.beginTransaction();
c = (Contract) s.createCriteria(Contract.class).uniqueResult();
assertEquals(c.getCustomerName(), "gavin");
assertEquals(c.getVariations().size(), 2);
Iterator it = c.getVariations().iterator();
cv1 = (ContractVariation) it.next();
assertEquals(cv1.getText(), "expensive");
cv2 = (ContractVariation) it.next();
assertEquals(cv2.getText(), "more expensive");
s.delete(c);
assertEquals(s.createCriteria(Contract.class).setProjection(Projections.rowCount()).uniqueResult(), new Long(0));
assertEquals(s.createCriteria(ContractVariation.class).setProjection(Projections.rowCount()).uniqueResult(), new Long(0));
t.commit();
s.close();
assertUpdateCount(0);
assertDeleteCount(3);
}
use of javax.persistence.PersistenceException in project hibernate-orm by hibernate.
the class ImmutableNaturalIdTest method testNaturalIdCheck.
@Test
public void testNaturalIdCheck() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
User u = new User("steve", "superSecret");
s.persist(u);
u.setUserName("Steve");
try {
s.flush();
fail();
} catch (PersistenceException e) {
//expected
t.rollback();
}
u.setUserName("steve");
s.delete(u);
s.close();
}
Aggregations