Hello all,
I'm trying to figure out how to do a query for objects and have associated objects loaded in one query rather than 1+n where n is the number of many-to-one mappings the object has. In the mapping for a Department object the properties for the organization and contact associations are as follows:
Code:
<many-to-one name="organization" column="organization_id" fetch="join" lazy="false" />
<many-to-one name="contact" column="contact_id" fetch="join" lazy="false" />
When I do a session.loadAll (Department.class), it does the join properly and returns a List of Department objects. But when I try and do the same thing via a query such as session.createQuery ("from Department as department join department.organization join department.contact order by department.name") it returns a tuple. That would be ok except that this is being done in my DAO and I want a List of Departments to return.
I tried using the query "select department from Department as department join department.organization join department.contact order by department.name", but then the individual queries for the organization and contact objects are still done.
I thought of maybe creating a wrapper around the List of tuples, but I'm not sure what to do with the some of the methods, like add(), remove(), etc.
So, how can I return a List of Departments and not have the organization and contact be lazily loaded?
Thanks,
Rich