O'Reilly logo

Hibernate Search by Example by Steve Perkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using JPA for queries

Although we will focus on the traditional query API, the downloadable source code also contains a different version of the example application in a chapter3-entitymanager folder. This VAPORware Marketplace variation demonstrates the use of JPA across the board, for both mapping and queries.

In the search controller servlet, rather than using a Hibernate SessionFactory object to create a Session object, it uses a JPA EntityManagerFactory instance to create an EntityManager object:

...
// The "com.packtpub.hibernatesearch.jpa" identifier is declared
// in "META-INF/persistence.xml"
EntityManagerFactory entityManagerFactory =
   Persistence.createEntityManagerFactory(
   "com.packtpub.hibernatesearch.jpa");
EntityManager entityManager ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required