Is it possible to filter by a count of a List(Set..'bag') property?

30 views
Skip to first unread message

bar...@gmail.com

unread,
Feb 10, 2015, 3:27:28 AM2/10/15
to java-gen...@googlegroups.com
My Entity is similar to that:
@Entity
public class Item implements Serializable {
 
@Id
 
private Long id;

 
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
 
private List<Sample> samples;
}

and i was wondering what is the best way (simple, clean, quick fetch, single query) to filter for the Items with the greater than 30 samples.size().

To make it clearer - we need to get only the Items which their samples collection size is bigger than 30.

Appreciate any assistance :)


bar...@gmail.com

unread,
Feb 10, 2015, 3:30:58 AM2/10/15
to java-gen...@googlegroups.com, bar...@gmail.com
Sorry.. i think i just found the solution it here:

Checking right now :)

bar...@gmail.com

unread,
Feb 10, 2015, 3:52:30 AM2/10/15
to java-gen...@googlegroups.com, bar...@gmail.com
Confirmed - this is working:
 Search search = new Search(Item.class);
 search
.addFilterCustom("?1 < (select count(*) from {samples})", 29l);
 
List<Item> items = this.search(search);

Thanks! :)


On Tuesday, February 10, 2015 at 10:27:28 AM UTC+2, bar...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages