HSEARCH-1793 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 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);
}
And:
final FullTextSession fullTextSession = ...;
List<?> results = fullTextSession.createFullTextQuery( query )
.setCriteriaProvider(
new CriteriaProvider {
public Criteria getCriteria(Class<?> entityType) {
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.
|