MyPropertySelector
package util;
import org.hibernate.criterion.Example.PropertySelector;
import org.hibernate.type.Type;
@SuppressWarnings("serial")
public class MyPropertySelector {
private static PropertySelector NOT_NULL_BLANK_ZEROS = null;
private MyPropertySelector(){
}
public static PropertySelector getNotNullBlankZeros() {
if(NOT_NULL_BLANK_ZEROS == null){
NOT_NULL_BLANK_ZEROS = new PropertySelector() {
public boolean include(Object value, String propertyName, Type type) {
return value != null
&& (((value instanceof String) && !("").equals(value))
|| ((value instanceof Number) && ((Number) value).longValue() != 0));
}
};
}
return NOT_NULL_BLANK_ZEROS;
}
}
Criteria c = session.createCriteria(Student.class);
l = c.add(Example.create(s)
.setPropertySelector(
MyPropertySelector.getNotNullBlankZeros())
.enableLike()
).list()