I was thinking more along the following lines:
Code:
x po=new x();
po.setA(a); // 'a' maybe null or with some valid value
po.setB(b);
po.setC(c);
Criteria crit=hibernateTemplate.createCriteria(x.class);
crit.add(Example.create(po));
By default null values set in po will not be considered as part of the criteria.
So e.g. if the values for a, b, c are null, b, c respectively.
Then only x(s) which match b and c would be returned. Since 'a' is null (could be equivalent to not filling in) it would be ignored and not included as part of the criteria.
The result would be similar to your code with null checks.
Quote:
But the result it's very strict ;becouse only return an existent object only if you fill all fields of the object. eg if I let in blank the form in the fields b,c just resturn an existent object with b,c null.
I do not agree with your above comments. It seems to me that your code (first post) should also have worked just fine. If a particular property is null then it is not added to the criteria. So the query should not include the property as part of the search.
It could be that when you do not fill in the field it may not be null but for e.g. an empty string "" or " ".
Check the query that is being generated and the value for the fields being left empty.