Search in sources :

Example 16 with JiraKey

use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.

the class HANAStoredProcedureTest method testStoredProcedureOutParameter.

@Test
@JiraKey("HHH-12138")
public void testStoredProcedureOutParameter(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        StoredProcedureQuery query = session.createStoredProcedureQuery("sp_count_phones");
        query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
        query.registerStoredProcedureParameter(2, Long.class, ParameterMode.OUT);
        query.setParameter(1, 1L);
        query.execute();
        Long phoneCount = (Long) query.getOutputParameterValue(2);
        assertEquals(Long.valueOf(2), phoneCount);
    });
}
Also used : StoredProcedureQuery(jakarta.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 17 with JiraKey

use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.

the class HANAStoredProcedureTest method testSysRefCursorAsOutParameter.

@Test
@JiraKey("HHH-12138")
public void testSysRefCursorAsOutParameter(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        StoredProcedureQuery function = session.createNamedStoredProcedureQuery("singleRefCursor");
        function.execute();
        Integer value = (Integer) function.getSingleResult();
        Assertions.assertFalse(function.hasMoreResults());
        assertEquals(Integer.valueOf(1), value);
    });
}
Also used : StoredProcedureQuery(jakarta.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 18 with JiraKey

use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.

the class HANAStoredProcedureTest method testStoredProcedureRefCursor.

@Test
@JiraKey("HHH-12138")
public void testStoredProcedureRefCursor(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        StoredProcedureQuery query = session.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();
        // noinspection unchecked
        List<Object[]> postComments = query.getResultList();
        Assertions.assertNotNull(postComments);
    });
}
Also used : StoredProcedureQuery(jakarta.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 19 with JiraKey

use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.

the class ResultTransformerTest method testResultTransformerIsAppliedToScrollableResults.

@Test
@JiraKey("HHH-3694")
public void testResultTransformerIsAppliedToScrollableResults(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        final PartnerA a = new PartnerA();
        a.setName("Partner A");
        final PartnerB b = new PartnerB();
        b.setName("Partner B");
        final Contract obj1 = new Contract();
        obj1.setName("Contract");
        obj1.setA(a);
        obj1.setB(b);
        session.persist(a);
        session.persist(b);
        session.persist(obj1);
    });
    scope.inSession((session) -> {
        Query q = session.getNamedQuery(Contract.class.getName() + ".testQuery");
        q.setFetchSize(100);
        q.setResultTransformer((ResultTransformer) (arg0, arg1) -> {
            // return only the PartnerA object from the query
            return ((Contract) arg0[0]).getA();
        });
        ScrollableResults sr = q.scroll();
        // does not support java.sql.ResultSet.first()
        if (scope.getSessionFactory().getJdbcServices().getDialect() instanceof AbstractHANADialect) {
            sr.next();
        } else {
            sr.first();
        }
        Object obj = sr.get();
        assertTrue(obj instanceof PartnerA);
        PartnerA obj2 = (PartnerA) obj;
        assertEquals("Partner A", obj2.getName());
    });
}
Also used : Test(org.junit.jupiter.api.Test) SessionFactoryScope(org.hibernate.testing.orm.junit.SessionFactoryScope) ScrollableResults(org.hibernate.ScrollableResults) AbstractHANADialect(org.hibernate.dialect.AbstractHANADialect) Query(org.hibernate.query.Query) Assert.assertTrue(org.junit.Assert.assertTrue) DomainModel(org.hibernate.testing.orm.junit.DomainModel) JiraKey(org.hibernate.testing.orm.junit.JiraKey) SessionFactory(org.hibernate.testing.orm.junit.SessionFactory) ResultTransformer(org.hibernate.transform.ResultTransformer) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractHANADialect(org.hibernate.dialect.AbstractHANADialect) Query(org.hibernate.query.Query) ScrollableResults(org.hibernate.ScrollableResults) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 20 with JiraKey

use of org.hibernate.testing.orm.junit.JiraKey in project hibernate-orm by hibernate.

the class ContributedUserTypeTest method test.

@Test
@JiraKey("HHH-14408")
public void test(SessionFactoryScope scope) {
    Type type = scope.getSessionFactory().getMappingMetamodel().getEntityDescriptor(StringWrapperTestEntity.class).getPropertyType("stringWrapper");
    Assertions.assertTrue(type instanceof CustomType, "Type was initialized too early i.e. before type-contributors were run");
}
Also used : CustomType(org.hibernate.type.CustomType) CustomType(org.hibernate.type.CustomType) Type(org.hibernate.type.Type) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Aggregations

JiraKey (org.hibernate.testing.orm.junit.JiraKey)20 Test (org.junit.jupiter.api.Test)20 SQLStatementInspector (org.hibernate.testing.jdbc.SQLStatementInspector)10 FailureExpected (org.hibernate.testing.orm.junit.FailureExpected)6 NamedStoredProcedureQuery (jakarta.persistence.NamedStoredProcedureQuery)5 StoredProcedureQuery (jakarta.persistence.StoredProcedureQuery)5 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)3 EntityManager (jakarta.persistence.EntityManager)2 AbstractMetamodelSpecificTest (org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest)2 Order (org.hibernate.orm.test.jpa.metamodel.Order)2 SkipForDialect (org.hibernate.testing.orm.junit.SkipForDialect)2 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)1 Predicate (jakarta.persistence.criteria.Predicate)1 ScrollableResults (org.hibernate.ScrollableResults)1 AbstractHANADialect (org.hibernate.dialect.AbstractHANADialect)1 Customer (org.hibernate.orm.test.jpa.metamodel.Customer)1 LineItem (org.hibernate.orm.test.jpa.metamodel.LineItem)1 ProcedureCall (org.hibernate.procedure.ProcedureCall)1 Query (org.hibernate.query.Query)1 Output (org.hibernate.result.Output)1