use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class StoredProcedureNullParameterByNameTest method testPassNull.
@Test
public void testPassNull() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
User user1 = new User();
user1.id = 1;
user1.name = "aName";
user1.age = 99;
em.persist(user1);
em.getTransaction().commit();
em.clear();
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.findNameById");
query.setParameter("ID_PARAM", 1);
// null is passed for EXTRA_IN_PARAM
assertEquals("aName", query.getOutputParameterValue("NAME_PARAM"));
assertEquals(null, query.getOutputParameterValue("EXTRA_OUT_PARAM"));
} finally {
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class DateTimeParameterTest method testBindingCalendarAsDate.
@Test
public void testBindingCalendarAsDate() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
StoredProcedureQuery query = em.createStoredProcedureQuery("findMessagesByDate");
query.registerStoredProcedureParameter(1, Calendar.class, ParameterMode.IN);
query.setParameter(1, nowCal, TemporalType.DATE);
List list = query.getResultList();
assertEquals(1, list.size());
} finally {
em.getTransaction().rollback();
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class HSQLStoreProcedureTest method testNamedStoredProcedureExecution.
@Test
@TestForIssue(jiraKey = "HHH-10515")
public void testNamedStoredProcedureExecution() {
EntityManager em = entityManagerFactory.createEntityManager();
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.inoutproc");
query.setParameter("arg1", 1);
query.execute();
} finally {
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class JpaTckUsageTest method testExecuteUpdate.
@Test
@FailureExpected(jiraKey = "HHH-8395", message = "Out of the frying pan into the fire: https://issues.apache.org/jira/browse/DERBY-211")
public void testExecuteUpdate() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
StoredProcedureQuery query = em.createStoredProcedureQuery("deleteAllUsers");
int count = query.executeUpdate();
// this fails because the Derby EmbeddedDriver is returning zero here rather than the actual updateCount :(
// https://issues.apache.org/jira/browse/DERBY-211
assertEquals(1, count);
} finally {
em.getTransaction().commit();
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class JpaTckUsageTest method testSettingNonExistingParams.
@Test
public void testSettingNonExistingParams() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
// non-existing positional param
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("positional-param");
query.setParameter(99, 1);
fail("Expecting an exception");
} catch (IllegalArgumentException expected) {
// this is the expected condition
}
// non-existing named param
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("positional-param");
query.setParameter("does-not-exist", 1);
fail("Expecting an exception");
} catch (IllegalArgumentException expected) {
// this is the expected condition
}
} finally {
em.getTransaction().commit();
em.close();
}
}
Aggregations