开发者

Seam - Entity Query - dynamic restrictions

开发者 https://www.devze.com 2023-02-06 04:43 出处:网络
I have an EntityQuery - addressList generated by Seam-gen for Entity Address. Lets say that address has following fields : streetName and city, so Seam-gen generate restrictions for them.

I have an EntityQuery - addressList generated by Seam-gen for Entity Address.

Lets say that address has following fields : streetName and city, so Seam-gen generate restrictions for them.

I would like to extend my EntityQue开发者_如何学运维ry with a following restrictions: I have a field 'keyVal' which can be set in faces context with #{addressList.keyVal}. Lets supose that keyVal is aaa bbb ccc. Now the query should add restrictions which will be used to find all entities with:

streetName like '%aaa%' or  streetName like '%bbb%' or streetName like '%ccc%' 
 or city like '%aaa%' or  city like '%bbb%' or city like '%ccc%'

Do you have any suggestions how to achieve this? I am really stucked.


The problem is EntityQuery does not support multiple value bindings on restrictions. See https://issues.jboss.org/browse/JBSEAM-1065

You can work around this sometimes by creative use of your criteria class.

You can sometimes look at modifying the query. For example, if I have a single staffName input and I need to query where staff first name like the input OR staff last name like input, I can write my query like this:

private static final String[] RESTRICTIONS = {
    "lower(concat(s.firstName, concat(' ', s.lastName))) like concat('%', 
               concat(lower(#{criteria.staffName}), '%'))"};

Hopefully this gives you some ideas.

0

精彩评论

暂无评论...
验证码 换一张
取 消