Search in sources :

Example 21 with FailureExpected

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

the class DeleteOneToManyOrphansTest method testOrphanedWhileManaged.

@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testOrphanedWhileManaged(EntityManagerFactoryScope scope) {
    Long productId = scope.fromTransaction(entityManager -> {
        List results = entityManager.createQuery("from Feature").getResultList();
        assertEquals(1, results.size());
        results = entityManager.createQuery("from Product").getResultList();
        assertEquals(1, results.size());
        Product product = (Product) results.get(0);
        assertEquals(1, product.getFeatures().size());
        product.getFeatures().clear();
        return product.getId();
    });
    scope.inTransaction(entityManager -> {
        Product _product = entityManager.find(Product.class, productId);
        assertEquals(0, _product.getFeatures().size());
        List results = entityManager.createQuery("from Feature").getResultList();
        assertEquals(0, results.size());
        results = entityManager.createQuery("from Product").getResultList();
        assertEquals(1, results.size());
    });
}
Also used : List(java.util.List) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 22 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected 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 23 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected 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 24 with FailureExpected

use of org.hibernate.testing.orm.junit.FailureExpected 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 25 with FailureExpected

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

the class SQLServerStoredProcedureCrossDatabaseTest method testStoredProcedureViaJPANamedParameters.

@Test
@FailureExpected(jiraKey = "HHH-12704", reason = "SQL Server JDBC Driver does not support registering name parameters properly")
public void testStoredProcedureViaJPANamedParameters(EntityManagerFactoryScope scope) {
    scope.inTransaction(entityManager -> {
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery(DATABASE_NAME + ".dbo.sp_square_number");
        query.registerStoredProcedureParameter("outputNumber", Integer.class, ParameterMode.OUT);
        query.setParameter("inputNumber", 7);
        query.execute();
        int result = (int) query.getOutputParameterValue("outputNumber");
        assertEquals(49, result);
    });
}
Also used : StoredProcedureQuery(jakarta.persistence.StoredProcedureQuery) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Aggregations

FailureExpected (org.hibernate.testing.orm.junit.FailureExpected)25 Test (org.junit.jupiter.api.Test)25 SQLStatementInspector (org.hibernate.testing.jdbc.SQLStatementInspector)6 JiraKey (org.hibernate.testing.orm.junit.JiraKey)6 List (java.util.List)5 TestForIssue (org.hibernate.testing.TestForIssue)4 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)3 Query (org.hibernate.query.Query)3 SelectionQuery (org.hibernate.query.SelectionQuery)3 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)2 UniqueConstraint (jakarta.persistence.UniqueConstraint)2 Date (java.util.Date)2 CollectionStatistics (org.hibernate.stat.CollectionStatistics)2 BaseUnitTest (org.hibernate.testing.orm.junit.BaseUnitTest)2 StoredProcedureQuery (jakarta.persistence.StoredProcedureQuery)1 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)1 Predicate (jakarta.persistence.criteria.Predicate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1