use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testHibernateProcedureCallReturnValueParameter.
@Test
public void testHibernateProcedureCallReturnValueParameter() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();
try {
Session session = entityManager.unwrap(Session.class);
ProcedureCall call = session.createStoredProcedureCall("sp_phones");
call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
Output output = call.getOutputs().getCurrent();
List<Object[]> personComments = ((ResultSetOutput) output).getResultList();
assertEquals(2, personComments.size());
} finally {
entityManager.getTransaction().rollback();
entityManager.close();
}
}
use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testHibernateProcedureCallReturnValueParameter.
@Test
public void testHibernateProcedureCallReturnValueParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
ProcedureCall call = session.createStoredProcedureCall("sp_phones");
call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
Output output = call.getOutputs().getCurrent();
List<Object[]> personComments = ((ResultSetOutput) output).getResultList();
assertEquals(2, personComments.size());
});
}
use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.
the class StoredProcedureResultSetMappingTest method testPartialResults.
@Test
public void testPartialResults() {
Configuration cfg = new Configuration().addAnnotatedClass(Employee.class).setProperty(AvailableSettings.HBM2DDL_AUTO, "create-drop");
cfg.addAuxiliaryDatabaseObject(new ProcedureDefinition());
SessionFactory sf = cfg.buildSessionFactory();
try {
Session session = sf.openSession();
session.beginTransaction();
ProcedureCall call = session.createStoredProcedureCall("allEmployeeNames", "id-fname-lname");
ProcedureOutputs outputs = call.getOutputs();
ResultSetOutput output = assertTyping(ResultSetOutput.class, outputs.getCurrent());
assertEquals(3, output.getResultList().size());
assertTyping(Employee.class, output.getResultList().get(0));
session.getTransaction().commit();
session.close();
} finally {
sf.close();
}
}
use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.
the class StoredProcedureTest method testInParametersByName.
// A warning should be logged if database metadata indicates named parameters are not supported.
@Test
public void testInParametersByName() {
Session session = openSession();
session.beginTransaction();
ProcedureCall query = session.createStoredProcedureCall("findUserRange");
query.registerParameter("start", Integer.class, ParameterMode.IN).bindValue(1);
query.registerParameter("end", Integer.class, ParameterMode.IN).bindValue(2);
ProcedureOutputs procedureResult = query.getOutputs();
Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
List results = resultSetReturn.getResultList();
assertEquals(1, results.size());
Object result = results.get(0);
assertTyping(Object[].class, result);
Integer id = (Integer) ((Object[]) result)[0];
String name = (String) ((Object[]) result)[1];
assertEquals(1, (int) id);
assertEquals("User 1", name);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.
the class StoredProcedureTest method testInParametersByPosition.
@Test
public void testInParametersByPosition() {
Session session = openSession();
session.beginTransaction();
ProcedureCall query = session.createStoredProcedureCall("findUserRange");
query.registerParameter(1, Integer.class, ParameterMode.IN).bindValue(1);
query.registerParameter(2, Integer.class, ParameterMode.IN).bindValue(2);
ProcedureOutputs procedureResult = query.getOutputs();
Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
List results = resultSetReturn.getResultList();
assertEquals(1, results.size());
Object result = results.get(0);
assertTyping(Object[].class, result);
Integer id = (Integer) ((Object[]) result)[0];
String name = (String) ((Object[]) result)[1];
assertEquals(1, (int) id);
assertEquals("User 1", name);
session.getTransaction().commit();
session.close();
}
Aggregations