use of org.hibernate.result.Output in project hibernate-orm by hibernate.
the class StoredProcedureTest method testGetSingleResultTuple.
@Test
public void testGetSingleResultTuple() {
Session session = openSession();
session.beginTransaction();
ProcedureCall query = session.createStoredProcedureCall("findOneUser");
ProcedureOutputs procedureResult = query.getOutputs();
Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
Object result = resultSetReturn.getSingleResult();
assertTyping(Object[].class, result);
String name = (String) ((Object[]) result)[1];
assertEquals("Steve", name);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.result.Output 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.Output in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testHibernateProcedureCallReturnValueParameter.
@Test
public void testHibernateProcedureCallReturnValueParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::sql-hibernate-call-sp-no-out-mysql-example[]
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();
// end::sql-hibernate-call-sp-no-out-mysql-example[]
assertEquals(2, personComments.size());
});
}
use of org.hibernate.result.Output in project hibernate-orm by hibernate.
the class ResultMappingTest method testResultClass.
@Test
public void testResultClass() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("findOneUser", H2ProcTesting.MyEntity.class);
final ProcedureOutputs procedureResult = call.getOutputs();
final Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
final ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
final Object result = resultSetReturn.getSingleResult();
assertTyping(H2ProcTesting.MyEntity.class, result);
assertEquals("Steve", ((H2ProcTesting.MyEntity) result).name);
});
}
use of org.hibernate.result.Output in project hibernate-orm by hibernate.
the class ResultMappingTest method testMappingNoFields.
@Test
public void testMappingNoFields() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("findOneUser", "no-fields");
final ProcedureOutputs procedureResult = call.getOutputs();
final Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
final ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
final Object result = resultSetReturn.getSingleResult();
assertTyping(H2ProcTesting.MyEntity.class, result);
assertEquals("Steve", ((H2ProcTesting.MyEntity) result).name);
});
}
Aggregations