Search in sources :

Example 1 with Product

use of org.hibernate.test.sql.hand.Product in project hibernate-orm by hibernate.

the class NativeSQLQueriesTest method testCompositeIdJoins.

@Test
@SuppressWarnings({ "unchecked" })
@FailureExpected(jiraKey = "unknown")
public void testCompositeIdJoins() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    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);
    s.save(product);
    s.save(order);
    s.save(person);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Product p = (Product) s.createQuery("from Product p join fetch p.orders").list().get(0);
    assertTrue(Hibernate.isInitialized(p.getOrders()));
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Object[] o = (Object[]) s.createSQLQuery("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);
    p = (Product) o[0];
    assertTrue(Hibernate.isInitialized(p.getOrders()));
    assertNotNull(p.getOrders().iterator().next());
    t.commit();
    s.close();
}
Also used : Order(org.hibernate.test.sql.hand.Order) Transaction(org.hibernate.Transaction) Product(org.hibernate.test.sql.hand.Product) Person(org.hibernate.test.sql.hand.Person) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Aggregations

Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 Order (org.hibernate.test.sql.hand.Order)1 Person (org.hibernate.test.sql.hand.Person)1 Product (org.hibernate.test.sql.hand.Product)1 FailureExpected (org.hibernate.testing.FailureExpected)1 Test (org.junit.Test)1