We're updating the issue view to help you get more done. 

Create extension point for plugging in Criteria providers

Description

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 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:

1 2 3 public interface CriteriaProvider { Criteria getCriteria(Class<?> entityType); }

And:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 final FullTextSession fullTextSession = ...; List<?> results = fullTextSession.createFullTextQuery( query ) .setCriteriaProvider( 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 ); } } } ) .list();

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.

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Gunnar Morling

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Priority

Major