I think you'll find that there are lots of classes and methods in the Hibernate Criteria API that allow you to do just that.
The Example object is great. Rather than they 'array of properties' you just initialize properties of an example instance of the POJO you're after, and create a Criterion out of it. It's so easy!
How to Use the Hibernate Criteria API: A Simple Tutorial
Code:
public static void main(String[] args) {
User user = new User();
user.setEmailAddress(".com");
Example example = Example.create(user);
example.enableLike(MatchMode.END);
Session session = HibernateUtil.beginTransaction();
Criteria criteria = session.createCriteria(User.class);
criteria.add(example); List results = criteria.list();
for (int i = 0; i<results.size(); i++) {
System.out.println(results.get(i).toString());
}
HibernateUtil.commitTransaction();
}
Code:
public static void main(String args[]) {
Session session = HibernateUtil.beginTransaction();
Criterion c1 = Restrictions.gt("id", (long)2);
Criterion c2 = Restrictions.lt("id", (long)8);
Criterion c3 = Restrictions.isNotNull("emailAddress");
User user = new User();
user.setEmailAddress(".com");
Example c4 = Example.create(user);
c4.enableLike(MatchMode.END);
c4.ignoreCase();
Criteria criteria = session.createCriteria(User.class);
criteria.add(c1);
criteria.add(c2);
criteria.add(c3);
criteria.add(c4);
List results = criteria.list();
HibernateUtil.commitTransaction();
for (int i = 0; i<results.size(); i++) {
System.out.println(results.get(i).toString());
}
}