The Criteria and Junction API seems to be a nice fit for a filtering use case we have that also requires logical operations.
In our DAO when building the Criteria object we determine what type of junction the user wishes to apply in this way:
Code:
...
//add the and or operation
if (staticFilter.isAndOperation()) {
junction = Expression.conjunction();
}
else {
junction = Expression.disjunction();
}
...
Generally, we add our criterion passed by our client in this way:
Code:
...
junction.add(Expression
.like("title", title, MatchMode.ANYWHERE).ignoreCase());
...
Later, we add the junction to a Criteria object.
Code:
...
Criteria criteria = session.createCriteria(SomeEntity.class).add(junction);
...
Further down, we also have some
additional criteria we add to the recently created criteria object:
Code:
...
criteria = criteria.createCriteria("metapropertiesValues");
criteria.add(Expression.eq("value", metapropertyValue));
criteria.add(Expression.eq("id.problemMetaproperty.id",
metapropertyKey));
...
Question:
We'd like the criteria's junction to apply to the additional criteria we specified above. Currently the criteria object would treat this as an "AND" type criteria only and of course disregards the previously added junction.
We're fairly new to the Criteria API. Is this possible? Can we have nested criteria that uses a single junction? We will have several of these nested criterias that we want to include in addition to the one above.
Or are we missing something?
Regards,
Roll