Search a collection size with attribute

39 views
Skip to first unread message

Tercio

unread,
Oct 28, 2011, 4:24:46 PM10/28/11
to java-generic-dao
Hi!

Is possible to create a filter with the operator SIZE but with a WHERE
clause?

Scenario:

public class A
{
private Set<B> bs;
}

public class B
{
private A a;
private boolean myProperty;
}

I want to get all As that have more than 3 Bs that have myProperty =
true.

If I use:

Search search = Search(A.class);
search.addFilterGreaterThan("bs.size", 3);

The "bs.size" get translated by hibernate to a sub-select using count,
but I need to add a WHERE clause to that sub-select(myProperty =
true).

Is that possible? I couldn't figure it out...

Thanks!

David Wolverton

unread,
Nov 9, 2011, 10:44:14 PM11/9/11
to java-gen...@googlegroups.com
I imagine it's way too late to answer this, but I think your only option is custom filter.

search.addFilterCustom("?1 < (select count(*) from {bs} bs where bs.myProperty = 1)", 3);

- David W.


--
You received this message because you are subscribed to the Google Groups "java-generic-dao" group.
To post to this group, send email to java-gen...@googlegroups.com.
To unsubscribe from this group, send email to java-generic-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/java-generic-dao?hl=en.


Reply all
Reply to author
Forward
0 new messages