findByCriteria in hibernate

In my generic Hibernate DAO which consists of a method findByCriteria

protected List<T> findByCriteria(Criterion... criterion) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        for (Criterion c : criterion) {
        return crit.list();

Now myDao extends generic dao.Now how can i use findByCriterion to get objects satisfying certain conditions.Can any one give some examples?


I do not know what dao.Now is but, you can use this method like this:

List<YourObject> result = findByCriteria("name", "Fritz%"));

Assuming that YourObject has a property name that should begin with Fritz

See documentation

Leave a Reply

Your email address will not be published. Required fields are marked *