[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5795) Allow Criteria#add(null)
Joachim Durchholz (JIRA)
noreply at atlassian.com
Wed Dec 15 12:06:13 EST 2010
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: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list