Search in sources :

Example 11 with ProcedureOutputs

use of org.hibernate.procedure.ProcedureOutputs in project hibernate-orm by hibernate.

the class StoredProcedureTest method testGetResultListTuple.

@Test
public void testGetResultListTuple() {
    Session session = openSession();
    session.beginTransaction();
    ProcedureCall query = session.createStoredProcedureCall("findUsers");
    ProcedureOutputs procedureResult = query.getOutputs();
    Output currentOutput = procedureResult.getCurrent();
    assertNotNull(currentOutput);
    ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
    List results = resultSetReturn.getResultList();
    assertEquals(3, results.size());
    for (Object result : results) {
        assertTyping(Object[].class, result);
        Integer id = (Integer) ((Object[]) result)[0];
        String name = (String) ((Object[]) result)[1];
        if (id.equals(1)) {
            assertEquals("Steve", name);
        } else if (id.equals(2)) {
            assertEquals("John", name);
        } else if (id.equals(3)) {
            assertEquals("Jane", name);
        } else {
            fail("Unexpected id value found [" + id + "]");
        }
    }
    session.getTransaction().commit();
    session.close();
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureOutputs(org.hibernate.procedure.ProcedureOutputs) ResultSetOutput(org.hibernate.result.ResultSetOutput) Output(org.hibernate.result.Output) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

ProcedureCall (org.hibernate.procedure.ProcedureCall)11 ProcedureOutputs (org.hibernate.procedure.ProcedureOutputs)11 ResultSetOutput (org.hibernate.result.ResultSetOutput)11 Test (org.junit.Test)11 Output (org.hibernate.result.Output)9 Session (org.hibernate.Session)7 List (java.util.List)3 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1