I've got a little
one-to-one problem.
I've got two classes with one-to-one relationship. For example: User and ContactInfo. Classes are bound together with primary keys. Relationship is uni-directional to be only possible to call user.getContactInfo(). Mapping for User looks as follows:
Code:
<one-to-one name="contactInfo" cascade="all" constrained="true" class="ContactInfo"/>
I've set outer join fetching ON and, so the load of a single user results in one SQL query joining User and ContactInfo tables. That's correct. But if I'd like all users with status=0, this HQL query results in n+1 SQL queries.
Code:
select user
from User as user
where user.status=0
First it selects all Users with status=0 and than selects for each User all data from User joining ContactInfo. If I change the HQL query a little, result is only one SQL query, but the resultset is a Collection of arrays (User and its ContactInfo).
Code:
select user, user.contactInfo
from User as user
where user.status=0
I know I can separate it in Java code, but I think there is much more elegant solution.
Thank for help. Sorry if this is a common problem, I wasn't able to find it here.
Pavel