Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-1852

Create extension point for plugging in Criteria providers


    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: query
    • Labels:


      HSEARCH-1793 Closed fixes an issue where cross-hierarchy queries (i.e. queries relating to entities with different id types and/or id property names) would fail. The fix for HSEARCH-1793 Closed creates a separate Criteria object for each hierarchy present in the ids to be loaded from the database.

      This conflicts though with the FullTextQuery#setCriteriaQuery() API which allows to pass in a single criteria object. One idea would be to deprecate and eventually remove setCriteriaQuery() and provide an extension point instead which allows to provide a custom criteria instance per entity type:

      public interface CriteriaProvider {
          Criteria getCriteria(Class<?> entityType);


      final FullTextSession fullTextSession = ...;
      List<?> results = fullTextSession.createFullTextQuery( query )
              new CriteriaProvider {
                  public Criteria getCriteria(Class<?> entityType) {
                      // for Book add a fetch join, everything else is defaulted
                      if ( entityType == Book.class ) {
                          return fullTextSession.createCriteria( Book.class ).setFetchMode( "authors", FetchMode.JOIN );
                      else {
                          return fullTextSession.createCriteria( entityType );

      On a related note, org.hibernate.search.jpa.FullTextQuery#setCriteriaQuery() expects a org.hibernate.Criteria instance instead of the JPA counter-part.

      Probably it'd make sense if the extension point described above works with the JPA criteria API in general, given that the Hibernate Criteria API is to be considered deprecated as per the ORM dev guide.


          Issue links



              • Assignee:
                gunnar.morling Gunnar Morling
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: