This works fine:
...
crit.setFetchMode("phones", FetchMode.JOIN);
...
// sometime later - session is now closed
// and contact has been populated from the query
contact.getPhones();
This does not work:
...
crit.setFetchMode("phones", FetchMode.JOIN);
crit.createAlias("phones", "ps");
crit.addOrder(Order.asc("ps.areaCode"));
...
// sometime later - session is now closed
// and contact has been populated from the query.
// Throws LazyInitializationException
contact.getPhones();
I also tried this:
...
crit.setFetchMode("phones", FetchMode.JOIN);
Criteria crit2 = crit.createCriteria("phones");
crit2.addOrder(Order.asc("areaCode"));
...
// sometime later - session is now closed
// and contact has been populated from the query.
// also throws LazyInitializationException
contact.getPhones();
Any idea how to get around this?
Thanks,
Ben
|