-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Issue accessing Collections on Query Result
PostPosted: Wed Apr 08, 2009 5:35 pm 
Newbie

Joined: Fri Oct 28, 2005 8:23 pm
Posts: 12
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...
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.