Search in sources :

Example 1 with Order

use of org.hibernate.orm.test.sql.hand.Order 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)

Aggregations

Order (org.hibernate.orm.test.sql.hand.Order)1 Person (org.hibernate.orm.test.sql.hand.Person)1 Product (org.hibernate.orm.test.sql.hand.Product)1 FailureExpected (org.hibernate.testing.orm.junit.FailureExpected)1 Test (org.junit.jupiter.api.Test)1