minor fixes for function call tests

This commit is contained in:
Steve Ebersole 2022-01-21 23:50:21 -06:00
parent dd41ebc3cf
commit bab5b2bf99
3 changed files with 15 additions and 50 deletions

View File

@ -378,40 +378,12 @@ public class OracleStoredProcedureTest {
);
}
@Test
public void testNamedNativeQueryStoredProcedureRefCursor(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
try {
List<Object[]> postAndComments = entityManager
.createNamedQuery(
"fn_person_and_phones" )
.setParameter( 1, 1L )
.getResultList();
Object[] postAndComment = postAndComments.get( 0 );
Person person = (Person) postAndComment[0];
Phone phone = (Phone) postAndComment[1];
assertEquals( 2, postAndComments.size() );
fail( "expected UnsupportedOperationException" );
}
catch (IllegalArgumentException ex) {
assertThat( ex.getCause(), instanceOf( UnsupportedOperationException.class ) );
assertEquals(
"Recognizing native query as a function call is no longer supported",
ex.getCause().getMessage()
);
}
}
);
}
@Test
public void testNamedProcedureCallStoredProcedureRefCursor(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
List<Object[]> postAndComments = entityManager
.createNamedStoredProcedureQuery(
"fn_person_and_phones_sq" )
.createNamedStoredProcedureQuery( "personAndPhonesFunction" )
.setParameter( 1, 1L )
.getResultList();
Object[] postAndComment = postAndComments.get( 0 );
@ -423,7 +395,7 @@ public class OracleStoredProcedureTest {
}
@Test
public void testNamedNativeQueryStoredProcedureRefCursorWithJDBC(EntityManagerFactoryScope scope) {
public void testFunctionCallWithJdbc(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Session session = entityManager.unwrap( Session.class );

View File

@ -442,7 +442,7 @@ public class HANAStoredProcedureTest extends BaseEntityManagerFunctionalTestCase
@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testNamedNativeQueryStoredProcedureRefCursorWithJDBC() {
public void testFunctionCallWithJDBC() {
EntityManager entityManager = createEntityManager();
entityManager.getTransaction().begin();

View File

@ -11,6 +11,7 @@ import java.util.Date;
import java.util.List;
import org.hibernate.annotations.NamedNativeQuery;
import org.hibernate.jpa.AvailableHints;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
@ -34,30 +35,22 @@ import static org.hibernate.jpa.HibernateHints.HINT_CALLABLE_FUNCTION;
/**
* @author Vlad Mihalcea
*/
@NamedNativeQuery(
name = "fn_person_and_phones",
query = "{ ? = call fn_person_and_phones( ? ) }",
callable = true,
resultSetMapping = "person_with_phones"
@NamedStoredProcedureQuery(
name = "personAndPhonesFunction",
procedureName = "fn_person_and_phones",
resultSetMappings = "personWithPhonesMapping",
parameters = @StoredProcedureParameter(type = Long.class),
hints = @QueryHint(name = HINT_CALLABLE_FUNCTION, value = "true")
)
@NamedNativeQuery(
name = "fn_person_and_phones_hana",
query = "select \"pr.id\", \"pr.name\", \"pr.nickName\", \"pr.address\", \"pr.createdOn\", \"pr.version\", \"ph.id\", \"ph.person_id\", \"ph.phone_number\", \"ph.valid\" from fn_person_and_phones( ? )",
callable = false,
resultSetMapping = "person_with_phones_hana"
)
@NamedStoredProcedureQuery(
name = "fn_person_and_phones_sq",
procedureName = "fn_person_and_phones",
resultSetMappings = "person_with_phones",
parameters = {
@StoredProcedureParameter(type = Long.class)
},
hints = @QueryHint(name = HINT_CALLABLE_FUNCTION, value = "true")
name = "fn_person_and_phones_hana",
query = "select \"pr.id\", \"pr.name\", \"pr.nickName\", \"pr.address\", \"pr.createdOn\", \"pr.version\", \"ph.id\", \"ph.person_id\", \"ph.phone_number\", \"ph.valid\" from fn_person_and_phones( ? )",
callable = false,
resultSetMapping = "person_with_phones_hana"
)
@SqlResultSetMappings({
@SqlResultSetMapping(
name = "person_with_phones",
name = "personWithPhonesMapping",
entities = {
@EntityResult(
entityClass = Person.class,