Search on a jpaquery


Firstly, i use hibernate search 6.
I would like to use hibernate search on a JPA Query.
My query return a List, not Entity, and every time return different results.

default List<HelperDTO> getHelperDTO(final List<BigInteger> ids, final EntityManager entityManager) {
		final QObjectA objectA = QObjectA .objectA;
		final QObjectB objectB= QObjectB .objectB;
		final JPAQuery<HelperDTO> query = new JPAQuery<>(entityManager);
		return QHelperDTO (, objectA.firstname, objectA.lastname,, objectB.firstname, objectB.lastname))
public class HelperDTO {
	private BigInteger objectAId;
	private String objectAFirstname;
	private String objectALastname;
    private BigInteger objectBId;
	private String objectBFirstname;
	private String objectBLastname;

Is it possible to use hibernate search on HelperDTO.class ? I think that it is not:grin:.

Thank you!


Hibernate Search has its own Search DSL. You cannot use JPA APIs to build Hibernate Search queries. That means you cannot use QueryDSL for JPA (which you seem to be using here) either.

In theory you could use a version of QueryDSL specifically for Hibernate Search, and that already exists, but it’s currently stuck on an older version of Hibernate Search.

Really, you should just use the Hibernate Search DSL directly.

A few tips to get you started:

Related answer on stackoverflow: How do I use a QueryDSL BooleanExpression in a Hibernate Search query? - Stack Overflow