Search in sources :

Example 11 with ResultSetOutput

use of org.hibernate.result.ResultSetOutput 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) Output(org.hibernate.result.Output) ResultSetOutput(org.hibernate.result.ResultSetOutput) List(java.util.List) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)11 ProcedureCall (org.hibernate.procedure.ProcedureCall)11 ResultSetOutput (org.hibernate.result.ResultSetOutput)11 Test (org.junit.Test)11 Output (org.hibernate.result.Output)9 ProcedureOutputs (org.hibernate.procedure.ProcedureOutputs)7 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)4 List (java.util.List)3 EntityManager (javax.persistence.EntityManager)2 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1