Skip to main content

Posts

Showing posts from October, 2011

How to write Like query in hibernate?

There will be situation to write search query in hibernate using like keyword. SQL: select * from users where username like '%test%'; the above in hibernate query: "select u from User u where u.userName like :username" pass parameter as "%searchstring%" the code will look like: List<User> userList = getEntityManager().createQuery("select u from User u where u.userName like :username").setParameter("username", "%"+q+"%").getResultList();