use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testHibernateProcedureCallOutParameter.
@Test
public void testHibernateProcedureCallOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::sql-hibernate-call-sp-out-mysql-example[]
Session session = entityManager.unwrap(Session.class);
ProcedureCall call = session.createStoredProcedureCall("sp_count_phones");
call.registerParameter("personId", Long.class, ParameterMode.IN).bindValue(1L);
call.registerParameter("phoneCount", Long.class, ParameterMode.OUT);
Long phoneCount = (Long) call.getOutputs().getOutputParameterValue("phoneCount");
assertEquals(Long.valueOf(2), phoneCount);
// end::sql-hibernate-call-sp-out-mysql-example[]
});
}
use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class OracleStoredProcedureTest method testHibernateProcedureCallRefCursor.
@Test
public void testHibernateProcedureCallRefCursor() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::sql-hibernate-call-sp-ref-cursor-oracle-example[]
Session session = entityManager.unwrap(Session.class);
ProcedureCall call = session.createStoredProcedureCall("sp_person_phones");
call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR);
Output output = call.getOutputs().getCurrent();
List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
assertEquals(2, postComments.size());
// end::sql-hibernate-call-sp-ref-cursor-oracle-example[]
});
}
use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class HANAStoredProcedureTest method testHibernateProcedureCallRefCursor.
@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testHibernateProcedureCallRefCursor() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();
try {
Session session = entityManager.unwrap(Session.class);
ProcedureCall call = session.createStoredProcedureCall("sp_person_phones");
call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR);
Output output = call.getOutputs().getCurrent();
List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
assertEquals(2, postComments.size());
} finally {
entityManager.getTransaction().rollback();
entityManager.close();
}
}
use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class StoredProcedureApiTests method testParameterBindTypeMismatch.
@Test
public void testParameterBindTypeMismatch() {
inTransaction(session -> {
try {
final ProcedureCall call1 = session.createStoredProcedureCall("test");
call1.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);
call1.setParameter(1, new Date());
fail("expecting failure");
} catch (IllegalArgumentException expected) {
}
});
}
use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class StoredProcedureApiTests method parameterValueAccess.
@Test
public void parameterValueAccess() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("test");
call.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);
call.registerStoredProcedureParameter(2, String.class, ParameterMode.OUT);
call.setParameter(1, 1);
call.getParameterValue(1);
});
}
Aggregations