Hello,
I'm trying to do something similar.
I'd like to get a list of beans Order, each one containing a Customer bean.
Used method is an SQL query, with addEntity (and addJoin if needed), without declaring associations into XML files.
Hibernate version: v3.1.3
Name and version of the database you are using: DB2
1) If I try something this way, I get a list of arrays containing 2 objets for each row.Code:
sess.createSQLQuery("SELECT c.*, m.* FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
.addEntity("cat", Cat.class)
.addEntity("mother", Cat.class)
2) This way I'm using a bean called OrderDisplay which contains all the datas from Order + an instance of Customer.Code:
StringBuffer sql = new StringBuffer();
sql.append("SELECT {ORDER.*},{CUSTOMER.*} ");
sql.append("FROM SCHEMA.ORDER ORDER, ");
sql.append("SCHEMA.CUSTOMER CUSTOMER ");
sql.append("WHERE ORDER.ID_CUSTOMER = CUSTOMER.ID_CUSTOMER ");
SQLQuery query = getSession().createSQLQuery(sql.toString());
query.addEntity("ORDER",OrderDisplay.class);
query.addJoin("CUSTOMER","ORDER.CUSTOMER");
List list = query.list();
my XML file OrderDisplay contains the following line :
Code:
<property column="CUSTOMER" name="customer" type="bla.bla.bla.Customer" />
result :
Quote:
could not resolve property: CUSTOMER of: bla.bla.bla.OrderDisplay
Any idea will be welcomed.
Thank you for reading me.
Tom