Here's a code fragment which builds a criterion array. The interesting part for us is the last "if" block -
I include the rest only for consistence with the log trace:
Code:
Collection<Criterion> criterion_list = new ArrayList<Criterion>();
if (channel_names != null && !channel_names.isEmpty()) {
Criterion channel_criterion = getChannelCriterion(channel_names);
criterion_list.add(channel_criterion);
} else {
criterion_list.add(Restrictions.isNotNull("channel_name"));
}
if (start_search != null) {
Criterion start_criterion = Restrictions.ge("starttid", start_search);
criterion_list.add(start_criterion);
}
if (end_search != null) {
Criterion end_criterion = Restrictions.le("starttid", end_search);
criterion_list.add(end_criterion);
}
if (title_string != null && title_string.trim().length() != 0) {
Criterion title_criterion = Restrictions.like("titel", MatchMode.ANYWHERE.toMatchString(title_string), MatchMode.ANYWHERE);
criterion_list.add(title_criterion);
}
if (description_string != null && description_string.trim().length() != 0) {
Criterion description_criterion1 = Restrictions.like("langomtale1", MatchMode.ANYWHERE.toMatchString(description_string), MatchMode.ANYWHERE);
Criterion description_criterion2 = Restrictions.like("kortomtale", MatchMode.ANYWHERE.toMatchString(description_string), MatchMode.ANYWHERE);
Criterion joint_description_criterion = Restrictions.or(description_criterion1, description_criterion2);
criterion_list.add(joint_description_criterion);
}
Criterion[] criterion_array = (Criterion[]) criterion_list.toArray(new Criterion[]{});
return findByCriteria(criterion_array);
Now I execute this with the variable "description_string" set to "%". Here is the logging trace
Code:
where
this_.channel_name=?
and this_.starttid>=?
and this_.starttid<=?
and (
this_.langomtale1 like ?
or this_.kortomtale like ?
)
TRACE StringType - binding 'tv2oj' to parameter: 1
TRACE TimestampType - binding '2009-10-04 10:05:00' to parameter: 2
TRACE TimestampType - binding '2009-10-04 23:05:00' to parameter: 3
TRACE StringType - binding '%%%%%' to parameter: 5
Parameter 4 is not bound and the query returns no results. My hibernate version is 3.3.0.SP1 (according to the
log).