use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class JpaTckUsageTest method testMultipleGetUpdateCountCalls.
@Test
public void testMultipleGetUpdateCountCalls() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
StoredProcedureQuery query = em.createStoredProcedureQuery("findOneUser");
// this is what the TCK attempts to do, don't shoot the messenger...
query.getUpdateCount();
// yep, twice
query.getUpdateCount();
} finally {
em.getTransaction().commit();
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class StoreProcedureOutParameterByNameTest method testTwoBasicOutParameters.
@Test
public void testTwoBasicOutParameters() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
User user = new User();
user.id = 1;
user.name = "aName";
user.age = 29;
em.persist(user);
em.getTransaction().commit();
em.clear();
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.findNameAndAgeById");
query.setParameter("ID_PARAM", 1);
assertEquals("aName", query.getOutputParameterValue("NAME_PARAM"));
assertEquals(29, query.getOutputParameterValue("AGE_PARAM"));
} finally {
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class SQLServerStoredProcedureTest method testStoredProcedureOutParameter.
@Test
public void testStoredProcedureOutParameter() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();
try {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones");
query.registerStoredProcedureParameter("personId", Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter("phoneCount", Long.class, ParameterMode.OUT);
query.setParameter("personId", 1L);
query.execute();
Long phoneCount = (Long) query.getOutputParameterValue("phoneCount");
assertEquals(Long.valueOf(2), phoneCount);
} finally {
entityManager.getTransaction().rollback();
entityManager.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class SQLServerStoredProcedureTest method testStoredProcedureRefCursor.
@Test
public void testStoredProcedureRefCursor() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();
try {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
query.setParameter(1, 1L);
query.execute();
List<Object[]> postComments = query.getResultList();
assertNotNull(postComments);
} catch (Exception e) {
assertTrue(Pattern.compile("Dialect .*? not known to support REF_CURSOR parameters").matcher(e.getCause().getMessage()).matches());
} finally {
entityManager.getTransaction().rollback();
entityManager.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testStoredProcedureReturnValue.
@Test
public void testStoredProcedureReturnValue() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();
try {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.setParameter(1, 1L);
List<Object[]> personComments = query.getResultList();
assertEquals(2, personComments.size());
} finally {
entityManager.getTransaction().rollback();
entityManager.close();
}
}
Aggregations