Search in sources :

Example 1 with JiraKey

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

the class PredicateTest method testByteArray.

/**
 * Check predicate for field which has simple byte array type (byte[]).
 */
@Test
@JiraKey("HHH-10603")
@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 12, reason = "Oracle12cDialect uses blob to store byte arrays and it's not possible to compare blobs with simple equality operators.")
public void testByteArray() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
    Root<Order> orderRoot = orderCriteria.from(Order.class);
    orderCriteria.select(orderRoot);
    Predicate p = builder.equal(orderRoot.get("number"), new byte[] { '1', '2' });
    orderCriteria.where(p);
    List<Order> orders = em.createQuery(orderCriteria).getResultList();
    assertTrue(orders.size() == 0);
    em.getTransaction().commit();
    em.close();
}
Also used : Order(org.hibernate.orm.test.jpa.metamodel.Order) EntityManager(jakarta.persistence.EntityManager) Predicate(jakarta.persistence.criteria.Predicate) SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) AbstractMetamodelSpecificTest(org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 2 with JiraKey

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

the class NotFoundIgnoreOneToOneTest method testQueryImplicitPathDereferencePredicate.

@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "Bad results due to cross-join")
public void testQueryImplicitPathDereferencePredicate(SessionFactoryScope scope) {
    final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
    statementInspector.clear();
    scope.inTransaction((session) -> {
        final String hql = "select c from Coin c where c.currency.id = 1";
        final List<Coin> coins = session.createQuery(hql, Coin.class).getResultList();
        assertThat(coins).hasSize(1);
        assertThat(coins.get(0).getCurrency()).isNull();
        // technically we could use a subsequent-select rather than a join...
        assertThat(statementInspector.getSqlQueries()).hasSize(1);
        assertThat(statementInspector.getSqlQueries().get(0)).contains(" join ");
        assertThat(statementInspector.getSqlQueries().get(0)).doesNotContain(" inner ");
    });
}
Also used : SQLStatementInspector(org.hibernate.testing.jdbc.SQLStatementInspector) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 3 with JiraKey

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

the class NotFoundIgnoreOneToOneTest method testQueryOwnerSelection.

@Test
@JiraKey("HHH-15060")
public void testQueryOwnerSelection(SessionFactoryScope scope) {
    final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
    statementInspector.clear();
    scope.inTransaction((session) -> {
        final String hql = "select c from Coin c";
        final List<Coin> coins = session.createQuery(hql, Coin.class).getResultList();
        assertThat(coins).hasSize(1);
        assertThat(coins.get(0).getCurrency()).isNull();
        // at the moment this uses a subsequent-select.  on the bright side, it is at least eagerly fetched.
        assertThat(statementInspector.getSqlQueries()).hasSize(2);
        assertThat(statementInspector.getSqlQueries().get(0)).contains(" from Coin ");
        assertThat(statementInspector.getSqlQueries().get(1)).contains(" from Currency ");
    // but I believe a jon would be better
    // assertThat( statementInspector.getSqlQueries() ).hasSize( 1 );
    // assertThat( statementInspector.getSqlQueries().get( 0 ) ).contains( " join " );
    // assertThat( statementInspector.getSqlQueries().get( 0 ) ).doesNotContain( " inner " );
    });
}
Also used : SQLStatementInspector(org.hibernate.testing.jdbc.SQLStatementInspector) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 4 with JiraKey

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

the class HANAStoredProcedureTest method testOutAndSysRefCursorAsOutParameter.

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

Example 5 with JiraKey

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

the class HANAStoredProcedureTest method testHibernateProcedureCallRefCursor.

@Test
@JiraKey("HHH-12138")
public void testHibernateProcedureCallRefCursor(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        ProcedureCall call = session.createStoredProcedureCall("sp_person_phones");
        final ProcedureParameter<Long> inParam = call.registerParameter(1, Long.class, ParameterMode.IN);
        call.setParameter(inParam, 1L);
        call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR);
        Output output = call.getOutputs().getCurrent();
        // noinspection unchecked
        List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
        assertEquals(2, postComments.size());
    });
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) Output(org.hibernate.result.Output) ResultSetOutput(org.hibernate.result.ResultSetOutput) 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