DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Marcos has posted 4 posts at DZone. View Full User Profile

Hibernate Query By Example

08.11.2008
| 10769 views |
  • submit to reddit
        // shows how to use hibernate query by example (QBE)

public List<Person> find(Person person) {

	Session session = getSession();

	Example example = Example.create(person)
				 .enableLike(MatchMode.ANYWHERE)
				 .excludeZeroes()
				 .ignoreCase();

	List<Person> result = session.createCriteria(Person.class)
				 .add(example)
				 .list();
							 
	return result;
}