use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testNativeQueryNullPositionalParameterParameter.
@Test
@TestForIssue(jiraKey = "HHH-10161")
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = Oracle8iDialect.class, comment = "ORA-00932: inconsistent datatypes: expected NUMBER got BINARY")
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNativeQueryNullPositionalParameterParameter() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
// native queries don't seem to flush by default ?!?
em.flush();
Query q = em.createNativeQuery("select * from Item i where i.intVal=?");
Parameter p = new Parameter() {
@Override
public String getName() {
return null;
}
@Override
public Integer getPosition() {
return 1;
}
@Override
public Class getParameterType() {
return Integer.class;
}
};
q.setParameter(p, null);
Parameter pGotten = q.getParameter(p.getPosition());
List results = q.getResultList();
// null != null
assertEquals(0, results.size());
q = em.createNativeQuery("select * from Item i where i.intVal is null and ? is null");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
q = em.createNativeQuery("select * from Item i where i.intVal is null or i.intVal = ?");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testNativeQueryNullNamedParameterParameter.
@Test
@TestForIssue(jiraKey = "HHH-10161")
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = Oracle8iDialect.class, comment = "ORA-00932: inconsistent datatypes: expected NUMBER got BINARY")
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNativeQueryNullNamedParameterParameter() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Item item = new Item("Mouse", "Micro$oft mouse");
em.persist(item);
// native queries don't seem to flush by default ?!?
em.flush();
Query q = em.createNativeQuery("select * from Item i where i.intVal=:iVal");
Parameter p = new Parameter() {
@Override
public String getName() {
return "iVal";
}
@Override
public Integer getPosition() {
return null;
}
@Override
public Class getParameterType() {
return Integer.class;
}
};
q.setParameter(p, null);
Parameter pGotten = q.getParameter(p.getName());
List results = q.getResultList();
assertEquals(0, results.size());
q = em.createNativeQuery("select * from Item i where (i.intVal is null) and (:iVal is null)");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
q = em.createNativeQuery("select * from Item i where i.intVal is null or i.intVal = :iVal");
q.setParameter(p, null);
results = q.getResultList();
assertEquals(1, results.size());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testNamedParameterWithUserError.
@Test
@TestForIssue(jiraKey = "HHH-10803")
public void testNamedParameterWithUserError() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Wallet w = new Wallet();
w.setBrand("Lacoste");
w.setModel("Minimic");
w.setSerial("0100202002");
em.persist(w);
em.flush();
Query jpaQuery = em.createQuery("select w from Wallet w");
try {
Parameter<?> parameter = jpaQuery.getParameter("brand");
fail("Should fail due to user error in parameters");
} catch (Exception e) {
assertTyping(IllegalArgumentException.class, e);
}
jpaQuery = em.createQuery("select w from Wallet w");
try {
Parameter<String> parameter = jpaQuery.getParameter("brand", String.class);
fail("Should fail due to user error in parameters");
} catch (Exception e) {
assertTyping(IllegalArgumentException.class, e);
}
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class TransactionJoiningTest method testIsJoinedAfterMarkedForRollbackExplicit.
@Test
@TestForIssue(jiraKey = "HHH-10807")
public void testIsJoinedAfterMarkedForRollbackExplicit() throws Exception {
assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
EntityManager entityManager = entityManagerFactory().createEntityManager(SynchronizationType.UNSYNCHRONIZED);
SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
assertTrue(entityManager.isOpen());
assertTrue(session.isOpen());
ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
entityManager.joinTransaction();
assertTrue(transactionCoordinator.isSynchronizationRegistered());
assertTrue(transactionCoordinator.isActive());
assertTrue(transactionCoordinator.isJoined());
transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
assertTrue(transactionCoordinator.isActive());
assertTrue(transactionCoordinator.isJoined());
assertTrue(entityManager.isJoinedToTransaction());
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
entityManager.close();
assertFalse(entityManager.isOpen());
assertFalse(session.isOpen());
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class TransactionJoiningTest method testMultiThreadTransactionTimeout.
/**
* In certain JTA environments (JBossTM, etc.), a background thread (reaper)
* can rollback a transaction if it times out. These timeouts are rare and
* typically come from server failures. However, we need to handle the
* multi-threaded nature of the transaction afterCompletion action.
* Emulate a timeout with a simple afterCompletion call in a thread.
* See HHH-7910
*/
@Test
@TestForIssue(jiraKey = "HHH-7910")
public void testMultiThreadTransactionTimeout() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
EntityManager em = entityManagerFactory().createEntityManager();
final SessionImpl sImpl = em.unwrap(SessionImpl.class);
final CountDownLatch latch = new CountDownLatch(1);
Thread thread = new Thread() {
public void run() {
((JtaTransactionCoordinatorImpl) sImpl.getTransactionCoordinator()).getSynchronizationCallbackCoordinator().afterCompletion(Status.STATUS_ROLLEDBACK);
latch.countDown();
}
};
thread.start();
latch.await();
boolean caught = false;
try {
em.persist(new Book("The Book of Foo", 1));
} catch (PersistenceException e) {
caught = e.getCause().getClass().equals(HibernateException.class);
}
assertTrue(caught);
// Ensure that the connection was closed by the background thread.
caught = false;
try {
em.createQuery("from Book").getResultList();
} catch (PersistenceException e) {
// HHH-9312
caught = true;
} catch (Exception e) {
caught = true;
}
assertTrue(caught);
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
em.close();
}
Aggregations