Hibernate query with like operator

Like operator
Follwoing method shows how to use the like operator in the hibernate quey.

  • Setting the querystring to search along with query as a parameter
  • enforcing case sensitive for searching upper case also.
  • return type is generis
  • Hibernate is simple t use in the queries

public List<password> getPasswordList(String search) {
   Query query =getSession().createQuery("from Password where upper(source) like :search order by source asc ");
   query.setParameter("search", "%"+search.toUpperCase()+"%");
         List pw =query.list();
         return pw;