开发者

HibernateEntityQuery and EJBQL restrictions

I've just inherited some code that uses HibernateEntityQuery and EJBQL restrictions.

There's an "activity" table/entity with various fields, and the existing EJBQL restrictions look like:

private final String[] SEARCHRESTRRICTION = { 
    "activity.startDate >= #{activityList.startMonthBeginDate}",
    "activity.startDate <= #{activityList.startMonthEndDate}",
    "activity.cost >= #{activityList.minCost}"
}

The table also has seven boolean fields representing days (sun/mon/tue...) which apply for a given activity. Now I'd like to query by days- the user will select days they are interested in, and the filtered results should include a开发者_JS百科ctivities which match any of the days chosen by the user.

For example, if the user checks mon/wed/fri, the query should return all activities for which mon = true OR wed = true OR fri = true.

The problem with EJBQL is that it applies the restrictions using AND, whereas I need to do something like:

select * from activity where
      (mon = true OR wed = true OR fri = true);

Is there a way to specify a restriction in the form of "return a result if ANY of the following are true"?


The solution was to move the initial filtering to the setEjbql() call, which is applied prior to the setRestrictionExpressionStrings().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜