-
1. Re: EntityQuery - restriction based on context value
monkeyden Jan 24, 2011 11:28 AM (in response to sirseam)A fewthings to mention:
First, I'm not sure how seam-gen creates it but I generally have a criteria object instance (an instance of the entity) to hold criteria.
private Address criteria; public get/setCriteria(){...}
Second, I only have a trailing wildcard in my code but I think Hibernate concat takes any number of args.
lower(address.keyVal) like concat('%', lower(#{addressList.criteria.keyVal}),'%')
Third, if it's not a persistent field, be sure to use the @Transient annotation.
Hope it helps
-
2. Re: EntityQuery - restriction based on context value
sirseam Jan 24, 2011 4:16 PM (in response to sirseam)Hello,
thanks for reply, but i want to create restriction that will strictly depend on value of 'keyVal'.
As i wrote the restriction should depend on the words in 'keyVal', not on the whole 'keyVal'... -
3. Re: EntityQuery - restriction based on context value
monkeyden Jan 24, 2011 9:32 PM (in response to sirseam)Ok, I see what you mean. It's an 'OR' on all the values parsed from keyVal. You're going to have to:
1. Parse the string and build that expression
2. Add it to the array of expressions
3. Set them in the base class, like so:setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
...where RESTRICTIONS is an String array of your EL expressions. I typically do this in the constructor but I don't know if you have the value of keyVal at that point. If not, you'll have to do it further downstream. Just don't build RESTRICTIONSs at query execution time (e.g. in getResultList()).