]
Joachim Durchholz commented on HHH-5795:
----------------------------------------
I found another workaround: I can always use Restrictions.sqlRestriction("1 =
1").
That unnecessarily complicates the work of Hibernate and the query optimizer, though.
Allow Criteria#add(null)
------------------------
Key: HHH-5795
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5795
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.6.0
Environment: Irrelevant
Reporter: Joachim Durchholz
Please allow using null as a Criterion in Criteria#add.
I'd like to write Criterion createFooBarFilter(x,y). It inspects both x and y, and
returns a Criterion that compares property foo with x and property bar with y, provided X
resp. Y are non-null (null values mean: do not filter).
If x is not null, the function returns Restrictions.eq("foo",x).
Likewise for Y.
If both are not null, return
Restrictions.and(Restrictions.eq("foo",x),Restrictions.eq("bar",y)).
I'd like to return null if both x and y are null. This would pass a null to
Criteria#add(null), but that crashes and burns miserably as soon as Hibernate wants to get
the SQL string from such a Criterion.
So... how about modifying CriteriaImpl#add like this:
public Criteria add(Criterion expression) {
if ( expression != null ) {
add( this, expression );
}
return this;
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: