Hibernate version: 3.2.4
Hibernate Mapping for MedOrders Collection on Resident. :
<list name="medorders" table="RESIDENT__MEDORDERS" cascade="none" inverse="false" lazy="true">
<key>
<column name="RESIDENT_ID" index="RESIDENT__MEDORDERS_FK" />
</key>
<list-index column="POS" />
<many-to-many class="com.sample.test.MedOrder" column="MEDORDERS_ID" />
</list>
Code:
List ww1 = retriever.getDao().createSQLQuery(
"select "
+ "{resident.*} ,{medorders.*} "
+" from RESIDENT__MEDORDERS re "
+ ", PERSON resident "
+ ", MEDORDERS medorders "
+ "where re.RESIDENT_ID = resident.id "
+ " and re.medorders_ID = medorders.id "
+ "and resident.id in (" + cleanSqlIds + ") "
).addEntity("resident",Resident.class)
.addEntity("medorders", MedOrder.class)
.list();
I am trying to execute the above query where medorders is a collection of type MedOrder on Resident Object.(Refer for Class Structure below)
After execution of above query, when I access medorders on Resident like resident.getmedorders().
I am seeing another query being executed by Hibernate to initialize the collection of medorders.
I am expecting that my initial query where I retrieving the parent object as well as its collection should initialize the collection on the parent object.
Question:
----------
I am wondering what should I do to get this collection initialized right after my query with out hibernate querying for initialization?
Note:
I cannot use criteria query with FetchMode.JOIN as I have query with lot of joins involving multiple tables.
Tables
-------
PERSON
MEDORDERS
RESIDENT__MEDORDERS (Join table for RESIDENT AND MEDORDERS)
Here is sample definition of Resident and Order.
Class Resident extends Person {
Long id;
int version ;
String dept;
//blah...
List<Order> medorders = new ArrayList<Order>();
}
Class Order {
Long id;
int version;
//blah...
}