Search in sources :

Example 1 with FailureExpected

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

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

the class NotFoundExceptionManyToOneTest method testGet.

@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "ObjectNotFoundException is thrown but caught and null is returned - see " + "org.hibernate.internal.SessionImpl.IdentifierLoadAccessImpl#doLoad")
public void testGet(SessionFactoryScope scope) {
    final SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
    statementInspector.clear();
    scope.inTransaction((session) -> {
        try {
            // should fail here loading the Coin due to missing currency (see NOTE#1)
            session.get(Coin.class, 1);
            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 3 with FailureExpected

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

the class NotFoundExceptionManyToOneTest method testQueryImplicitPathDereferencePredicate.

@Test
@JiraKey("HHH-15060")
@FailureExpected(reason = "EntityNotFoundException thrown rather than ObjectNotFoundException; " + "ObjectNotFoundException is thrown but caught and then converted to EntityNotFoundException")
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";
        try {
            session.createQuery(hql, Coin.class).getResultList();
            fail("Expecting ObjectNotFoundException for broken fk");
        } catch (ObjectNotFoundException expected) {
            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 4 with FailureExpected

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

the class NativeSQLQueriesTest method testCompositeIdJoins.

@Test
@SuppressWarnings({ "unchecked" })
@FailureExpected(jiraKey = "unknown")
public void testCompositeIdJoins(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        Person person = new Person();
        person.setName("Noob");
        Product product = new Product();
        product.setProductId(new Product.ProductId());
        product.getProductId().setOrgid("x");
        product.getProductId().setProductnumber("1234");
        product.setName("Hibernate 3");
        Order order = new Order();
        order.setOrderId(new Order.OrderId());
        order.getOrderId().setOrdernumber("1");
        order.getOrderId().setOrgid("y");
        product.getOrders().add(order);
        order.setProduct(product);
        order.setPerson(person);
        session.save(product);
        session.save(order);
        session.save(person);
    });
    scope.inTransaction(session -> {
        Product p = (Product) session.createQuery("from Product p join fetch p.orders").list().get(0);
        assertTrue(Hibernate.isInitialized(p.getOrders()));
    });
    scope.inTransaction(session -> {
        Object[] o = (Object[]) session.createNativeQuery("select\r\n" + "        product.orgid as {product.id.orgid}," + "        product.productnumber as {product.id.productnumber}," + "        {prod_orders}.orgid as orgid3_1_,\r\n" + "        {prod_orders}.ordernumber as ordernum2_3_1_,\r\n" + "        product.name as {product.name}," + "        {prod_orders.element.*}" + /*"        orders.PROD_NO as PROD4_3_1_,\r\n" +
				"        orders.person as person3_1_,\r\n" +
				"        orders.PROD_ORGID as PROD3_0__,\r\n" +
				"        orders.PROD_NO as PROD4_0__,\r\n" +
				"        orders.orgid as orgid0__,\r\n" +
				"        orders.ordernumber as ordernum2_0__ \r\n" +*/
        "from\r\n" + "        Product product \r\n" + "    inner join\r\n" + "        TBL_ORDER {prod_orders} \r\n" + "            on product.orgid={prod_orders}.PROD_ORGID \r\n" + "            and product.productnumber={prod_orders}.PROD_NO").addEntity("product", Product.class).addJoin("prod_orders", "product.orders").list().get(0);
        Product p = (Product) o[0];
        assertTrue(Hibernate.isInitialized(p.getOrders()));
        assertNotNull(p.getOrders().iterator().next());
    });
}
Also used : Order(org.hibernate.orm.test.sql.hand.Order) Product(org.hibernate.orm.test.sql.hand.Product) Person(org.hibernate.orm.test.sql.hand.Person) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected)

Example 5 with FailureExpected

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

the class MappedSuperclassType2Test method testMappedSuperclassAccessNoEntity.

@Test
@TestForIssue(jiraKey = "HHH-8534")
@FailureExpected(jiraKey = "HHH-8534")
public void testMappedSuperclassAccessNoEntity() {
    // stupid? yes.  tck does it? yes.
    final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {

        @Override
        public List<String> getManagedClassNames() {
            // pass in a MappedSuperclass that is not used in any entity hierarchy
            return Arrays.asList(SomeMappedSuperclass.class.getName());
        }
    };
    final Map settings = new HashMap();
    settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
    EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
    try {
        ManagedType<SomeMappedSuperclass> type = emf.getMetamodel().managedType(SomeMappedSuperclass.class);
        // the issue was in regards to throwing an exception, but also check for nullness
        assertNotNull(type);
    } finally {
        emf.close();
    }
}
Also used : HashMap(java.util.HashMap) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) PersistenceUnitDescriptorAdapter(org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter) HashMap(java.util.HashMap) Map(java.util.Map) BaseUnitTest(org.hibernate.testing.orm.junit.BaseUnitTest) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

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