Hibernate Wildcard Query

Examples

hibernate_icon

Creating a wildcard query in Hibernate (HQL) is similar to how SQL handles the same funciton. The query is accomplished by using the, like keyword.

The example below searches for people with a name that contains Mik – an obvious match would be Mike.

Query query
= getEntityManager().createQuery("SELECT p FROM Person p WHERE p.name like :name");
 query.setParameter("name", 'Mik");
 query.getResultList(); // Returns a list of People.
No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>