-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Initializing a collection returned by session.filter() ?
PostPosted: Tue Dec 07, 2004 9:48 am 
Newbie

Joined: Wed Dec 01, 2004 12:27 pm
Posts: 11
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.