Hello
Consider the following simplified piece of code :
Team team = (Team)session.load(Team.class, id);
session.filter(team.getPlayers(),"order by this.scoredGoals"); // i.e just sort team players by scored goals
return team;
However, if I try to access team.Players (which is a set in Team.hbm.xml for my one-to-many association with the Player class), I am getting a "Failure to lazily initialize a collection" exception, which is I presume correct because filter() does not initialize.
I've tried :
Set players = (Set)session.filter(team.getPlayers(),"order by this.scoredGoals");
players.size(); // force load to initialize
team.setPlayers(players);
But it serves a java.lang.ClassCastException :-
Can I initialize this returned collection, but still ordered with filter() and is the filter() ordering approach correct ?
Thanks for any advice
|