Question

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 activities 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"?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top