use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class StoredProcedureTest method testInParametersNotSet.
@Test
public void testInParametersNotSet() {
Session session = openSession();
session.beginTransaction();
// since the procedure does not define defaults for parameters this should result in SQLExceptions on
// execution
{
ProcedureCall query = session.createStoredProcedureCall("findUserRange");
query.registerParameter(1, Integer.class, ParameterMode.IN);
query.registerParameter(2, Integer.class, ParameterMode.IN).bindValue(2);
try {
query.getOutputs();
fail("Expecting failure due to missing parameter bind");
} catch (JDBCException expected) {
}
}
// H2 does not support named parameters
// {
// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
// query.registerParameter( "start", Integer.class, ParameterMode.IN );
// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 );
// try {
// query.getOutputs();
// fail( "Expecting failure due to missing parameter bind" );
// }
// catch (JDBCException expected) {
// }
// }
session.getTransaction().commit();
session.close();
}
use of org.hibernate.procedure.ProcedureCall 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.procedure.ProcedureCall 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();
}
Aggregations