OK guys. Thanks a million for the advice with aliases and nested criterias.
It works, but I don't like the additiona lines of code I have to write ;-)
Furthermore, when I examined SQL queries got confused one more time.
HQL Query produces following SQL query:
Code:
select child.id, child.name, child.parent_id
from child, parent
where child.parent_id=parent.id
order by parent.name
Criteria API produces this one:
Code:
select child.id, child.name, child.parent_id, parent.id, parent.name
from child inner join parent on child.parent_id=parent.id
order by parent.name asc
They look very similar but there is a significant differnece. HQL-based query don't load all properties for parent object, but uses lazy loading. Criteria API query seem to initialize entire graph of objects. I've tried:
Code:
criteria.setFetchMode("parent", FetchMode.SELECT);
, but unfortunatelly it hasn't work.
Do you, guys, have and comments on this?
Cheers,
Tom