Search on a jpaquery

Hi,

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 query.select(new QHelperDTO (objectA.id, objectA.firstname, objectA.lastname, objectB.id, objectB.firstname, objectB.lastname))
				.from(objectB)
				.innerJoin(objectA).on(objectB.objectA.id.eq(objectB.id))
				.where(objectA.id.in(ids))
				.fetch();
	}
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!

Hey,

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