Class Search

java.lang.Object
org.hibernate.search.mapper.orm.Search

public final class Search extends Object
  • Method Details

    • mapping

      public static SearchMapping mapping(SessionFactory sessionFactory)
      Retrieve the SearchMapping from a Hibernate ORM SessionFactory.
      Parameters:
      sessionFactory - A Hibernate ORM session factory.
      Returns:
      The corresponding SearchSession.
      Throws:
      SearchException - if the session NOT SharedSessionContract.isOpen().
    • mapping

      public static SearchMapping mapping(jakarta.persistence.EntityManagerFactory entityManagerFactory)
      Retrieve the SearchMapping from a JPA EntityManagerFactory.
      Parameters:
      entityManagerFactory - A JPA entity manager factory.
      Returns:
      The corresponding SearchSession.
      Throws:
      SearchException - if the session NOT SharedSessionContract.isOpen().
    • session

      public static SearchSession session(Session session)
      Retrieve the SearchSession from a Hibernate ORM Session.

      The resulting instance depends on the passed Session: closing the Session will close the SearchSession. The SearchSession will share the Session's persistence context.

      Parameters:
      session - A Hibernate ORM session.
      Returns:
      The corresponding SearchSession.
      Throws:
      SearchException - if the session NOT SharedSessionContract.isOpen().
    • session

      public static SearchSession session(jakarta.persistence.EntityManager entityManager)
      Retrieve the SearchSession from a JPA EntityManager.

      The resulting instance depends on the passed EntityManager: closing the EntityManager will close the SearchSession. The SearchSession will share the EntityManager's persistence context.

      Parameters:
      entityManager - A JPA entity manager.
      Returns:
      The corresponding SearchSession.
      Throws:
      SearchException - if the entity manager NOT EntityManager.isOpen().
    • toJpaQuery

      public static <H> jakarta.persistence.TypedQuery<H> toJpaQuery(SearchQuery<H> searchQuery)
      Convert a SearchQuery to a JPA query.

      Note that the resulting query does not support all operations and may behave slightly differently from what is expected from a TypedQuery in some cases (including, but not limited to, the type of thrown exceptions). For these reasons, it is recommended to only use this method when absolutely required, for example when integrating to an external library that expects JPA queries.

      Type Parameters:
      H - The type of query hits.
      Parameters:
      searchQuery - The search query to convert.
      Returns:
      A representation of the given query as a JPA query.
    • toOrmQuery

      public static <H> Query<H> toOrmQuery(SearchQuery<H> searchQuery)
      Convert a SearchQuery to a Hibernate ORM query.

      Note that the resulting query does not support all operations and may behave slightly differently from what is expected from a Query in some cases (including, but not limited to, the type of thrown exceptions). For these reasons, it is recommended to only use this method when absolutely required, for example when integrating to an external library that expects Hibernate ORM queries.

      Type Parameters:
      H - The type of query hits.
      Parameters:
      searchQuery - The search query to convert.
      Returns:
      A representation of the given query as a Hibernate ORM query.