use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class OracleStoredProcedureTest method testSysRefCursorAsOutParameter.
@Test
@TestForIssue(jiraKey = "HHH-11863")
public void testSysRefCursorAsOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
StoredProcedureQuery function = entityManager.createNamedStoredProcedureQuery("singleRefCursor");
function.execute();
assertFalse(function.hasMoreResults());
Long value = null;
try (ResultSet resultSet = (ResultSet) function.getOutputParameterValue(1)) {
while (resultSet.next()) {
value = resultSet.getLong(1);
}
} catch (SQLException e) {
fail(e.getMessage());
}
assertEquals(Long.valueOf(1), value);
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class OracleStoredProcedureTest method testOutAndSysRefCursorAsOutParameter.
@Test
@TestForIssue(jiraKey = "HHH-11863")
public void testOutAndSysRefCursorAsOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
StoredProcedureQuery function = entityManager.createNamedStoredProcedureQuery("outAndRefCursor");
function.execute();
assertFalse(function.hasMoreResults());
Long value = null;
try (ResultSet resultSet = (ResultSet) function.getOutputParameterValue(1)) {
while (resultSet.next()) {
value = resultSet.getLong(1);
}
} catch (SQLException e) {
fail(e.getMessage());
}
assertEquals(value, function.getOutputParameterValue(2));
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class OracleStoredProcedureTest method testStoredProcedureRefCursor.
@Test
public void testStoredProcedureRefCursor() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();
try {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_person_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
query.setParameter(1, 1L);
query.execute();
List<Object[]> postComments = query.getResultList();
assertNotNull(postComments);
} finally {
entityManager.getTransaction().rollback();
entityManager.close();
}
}
use of javax.persistence.StoredProcedureQuery in project tutorials by eugenp.
the class StoredProcedureIntegrationTest method findCarsByYearNamedProcedure.
@Test
public void findCarsByYearNamedProcedure() {
final StoredProcedureQuery findByYearProcedure = entityManager.createNamedStoredProcedureQuery("findByYearProcedure");
final StoredProcedureQuery storedProcedure = findByYearProcedure.setParameter("p_year", 2015);
storedProcedure.getResultList().forEach(c -> Assert.assertEquals(new Integer(2015), ((Car) c).getYear()));
}
use of javax.persistence.StoredProcedureQuery in project tutorials by eugenp.
the class StoredProcedureIntegrationTest method findCarsByYearNoNamed.
@Test
public void findCarsByYearNoNamed() {
final StoredProcedureQuery storedProcedure = entityManager.createStoredProcedureQuery("FIND_CAR_BY_YEAR", Car.class).registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN).setParameter(1, 2015);
storedProcedure.getResultList().forEach(c -> Assert.assertEquals(new Integer(2015), ((Car) c).getYear()));
}
Aggregations