Search in sources :

Example 11 with JiraKey

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

the class NotFoundExceptionManyToOneTest method testQueryOwnerSelection.

@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "EntityNotFoundException thrown rather than ObjectNotFoundException; " + "ObjectNotFoundException is thrown but caught and then converted to EntityNotFoundException")
public void testQueryOwnerSelection(SessionFactoryScope scope) {
    final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
    statementInspector.clear();
    scope.inTransaction((session) -> {
        final String hql = "select c from Coin c";
        try {
            session.createQuery(hql, Coin.class).getResultList();
            fail("Expecting ObjectNotFoundException for broken fk");
        } catch (ObjectNotFoundException expected) {
            // 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 ");
            assertThat(expected.getEntityName()).isEqualTo(Currency.class.getName());
            assertThat(expected.getIdentifier()).isEqualTo(1);
        }
    });
}
Also used : SQLStatementInspector(org.hibernate.testing.jdbc.SQLStatementInspector) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 12 with JiraKey

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

the class NotFoundIgnoreOneToOneTest method testGet.

@Test
@JiraKey("HHH-15060")
public void testGet(SessionFactoryScope scope) {
    final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
    statementInspector.clear();
    scope.inTransaction((session) -> {
        final Coin coin = session.get(Coin.class, 1);
        assertThat(coin.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) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 13 with JiraKey

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

the class NotFoundIgnoreManyToOneTest method testQueryAssociationSelection.

@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "Has zero results because of inner-join; & the select w/ inner-join is executed twice for some odd reason")
public void testQueryAssociationSelection(SessionFactoryScope scope) {
    final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
    statementInspector.clear();
    scope.inTransaction((session) -> {
        final String hql = "select c.currency from Coin c";
        session.createQuery(hql, Currency.class).getResultList();
        final List<Currency> currencies = session.createSelectionQuery(hql, Currency.class).getResultList();
        assertThat(currencies).hasSize(1);
        assertThat(currencies.get(0)).isNull();
        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 14 with JiraKey

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

the class NotFoundIgnoreManyToOneTest 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.createSelectionQuery(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 15 with JiraKey

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

the class HANAStoredProcedureTest method testBindParameterAsHibernateType.

@Test
@JiraKey("HHH-12661")
public void testBindParameterAsHibernateType(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        StoredProcedureQuery query = session.createStoredProcedureQuery("sp_phone_validity").registerStoredProcedureParameter(1, NumericBooleanConverter.class, ParameterMode.IN).registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR).setParameter(1, true);
        query.execute();
        List<?> phones = query.getResultList();
        assertEquals(1, phones.size());
        assertEquals("123-456-7890", phones.get(0));
    });
    scope.inTransaction((session) -> {
        Vote vote1 = new Vote();
        vote1.setId(1L);
        vote1.setVoteChoice(true);
        session.persist(vote1);
        Vote vote2 = new Vote();
        vote2.setId(2L);
        vote2.setVoteChoice(false);
        session.persist(vote2);
    });
    scope.inTransaction((session) -> {
        StoredProcedureQuery query = session.createStoredProcedureQuery("sp_votes").registerStoredProcedureParameter(1, YesNoConverter.class, ParameterMode.IN).registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR).setParameter(1, true);
        query.execute();
        List<?> votes = query.getResultList();
        assertEquals(1, votes.size());
        assertEquals(1, ((Number) votes.get(0)).intValue());
    });
}
Also used : StoredProcedureQuery(jakarta.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery) 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