use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testStoredProcedureRefCursor.
@Test
public void testStoredProcedureRefCursor() {
try {
doInJPA(this::entityManagerFactory, entityManager -> {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_phones");
query.registerStoredProcedureParameter(1, void.class, ParameterMode.REF_CURSOR);
query.registerStoredProcedureParameter(2, Long.class, ParameterMode.IN);
query.setParameter(2, 1L);
List<Object[]> personComments = query.getResultList();
assertEquals(2, personComments.size());
});
} catch (Exception e) {
assertTrue(Pattern.compile("Dialect .*? not known to support REF_CURSOR parameters").matcher(e.getCause().getMessage()).matches());
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class OracleStoredProcedureTest method testStoredProcedureOutParameter.
@Test
public void testStoredProcedureOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter(2, Long.class, ParameterMode.OUT);
query.setParameter(1, 1L);
query.execute();
Long phoneCount = (Long) query.getOutputParameterValue(2);
assertEquals(Long.valueOf(2), phoneCount);
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class StoreProcedureOutParameterByPositionTest method testOneBasicOutParameter.
@Test
public void testOneBasicOutParameter() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
User user = new User();
user.id = 1;
user.name = "aName";
em.persist(user);
em.getTransaction().commit();
em.clear();
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.findNameById");
query.setParameter(1, 1);
assertEquals("aName", query.getOutputParameterValue(2));
} finally {
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class StoreProcedureOutParameterByPositionTest 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(1, 1);
assertEquals("aName", query.getOutputParameterValue(2));
assertEquals(29, query.getOutputParameterValue(3));
} finally {
em.close();
}
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class StoreProcedureRefCursorOutParameterByNameTest method testNamedStoredProcedureExecution.
@Test
public void testNamedStoredProcedureExecution() {
EntityManager em = entityManagerFactory.createEntityManager();
try {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.findByName");
query.setParameter("USER_NAME_PARAM", "my_name");
query.getResultList();
} finally {
em.close();
}
}
Aggregations