Thanks for your reply dungakishore,
Class FetchMode has not (according to javadocs) subselect field. You have three choices: default, join, select (lazy and eager are deprecated)
According to hibernate reference fetch strategy should be left in hbm file as is and changed at runtime as needed. But I can't see api to accomplish that.
Using join strategy for optimisation has consequence in duplicated object returned by query and batch and subselect has not.
Another matter is why only left outer join cause related collection loaded eagerly (inner join not)
reffering to my example with person and accounts:
Code:
DetachedCriteria nonLazyTest = DetachedCriteria("Person.Class")
.createCriteria("accounts", Criteria.LEFT_JOIN)
.add(some restrictions...)
will cause accounts collection loaded in one select with persons but in example below:
Code:
DetachedCriteria nonLazyTest = DetachedCriteria("Person.Class")
.createCriteria("accounts", Criteria.INNER_JOIN)
.add(some restrictions...)
accounts collection need to be initalized or you will get LazyInitializationException if you try to refer accounts outside session scope