Case-insensitive search using Hibernate

前端 未结 9 1202
长情又很酷
长情又很酷 2021-01-30 16:13

I\'m using Hibernate for ORM of my Java app to an Oracle database (not that the database vendor matters, we may switch to another database one day), and I want to retrieve objec

9条回答
  •  死守一世寂寞
    2021-01-30 16:49

    This can also be done using the criterion Example, in the org.hibernate.criterion package.

    public List findLike(Object entity, MatchMode matchMode) {
        Example example = Example.create(entity);
        example.enableLike(matchMode);
        example.ignoreCase();
        return getSession().createCriteria(entity.getClass()).add(
                example).list();
    }
    

    Just another way that I find useful to accomplish the above.

提交回复
热议问题