Reputation: 7082
I'm using JPA in PlayFramwork.
I have a class Page with a field of HashSet
Set<PageStatus> pageStatus= new HashSet<PageStatus>();
I want to find Page with Page.find("pageStatus like ?", status).fetch()
and it failed with exception
Caused by: java.lang.IllegalArgumentException: Parameter value [LATEST] was not matching type [java.util.Set]
status is a HashSet with these code
Set<PageStatus> statuses = new HashSet<PageStatus>();
statuses.add(PageStatus.LATEST);
Any suggestion? thanks.
Upvotes: 2
Views: 480
Reputation: 16439
The problem is that you are trying to filter by an M - N relation. That is, you have in one side a Set A and in the other a second Set B.
IN
won't work as it's used to determine that a single element is inside a collection of elements. Like: element x is in the given {array, list, set} z. In your scenario you have 2 sets, this won't work.Like
compares Strings directly. For example, a String A is similar to a String B. You have two sets, it won't work either.From your example, you want to filter by an element inside a Set of your entity. Try this:
PageStatus statuses = PageStatus.LATEST;
Page.find("(?1) in pageStatus", statuses).fetch()
If you want to filter by multiple elements, you'll have to concatenate the filters with or
.
Upvotes: 1
Reputation: 3833
You cannot use a Set as an argument for a like clause. A like needs a string as the parameter. The only clause that can work with Set is the in
clause
Upvotes: 1