Bizzare compilation time error with ORM 6.1.5 and Jakarta

In the IDE there are no errors for this code:

CriteriaBuilder criteriaBuilder = infoPersonAddressDAO.getEntityManager().getCriteriaBuilder();
CriteriaQuery<Date> criteriaQuery = criteriaBuilder.createQuery(Date.class);

Root<InfoPersonAddress> root = criteriaQuery.from(InfoPersonAddress.class);
criteriaQuery.select(criteriaBuilder.least(root.get(InfoPersonAddress.FIELD_NAME_CREATED_WHEN)));

TypedQuery<Date> queryData = infoPersonAddressDAO.getEntityManager().createQuery(criteriaQuery);

result = queryData.getSingleResult();

During Maven build with OpenJDK 17.0.5 on MacOS/ARM, I get this:

[e[1;31mERRORe[m] /Users/acm/dev/projects/Java/logipath/pirt/pirt-ejb/src/main/java/com/logipath/pirt/helper/info/person/address/InfoPersonAddressDTODAOImpl.java:[122,61] method least in interface jakarta.persistence.criteria.CriteriaBuilder cannot be applied to given types;
[e[1;31mERRORe[m]   required: jakarta.persistence.criteria.Expression<X>
[e[1;31mERRORe[m]   found:    jakarta.persistence.criteria.Path<java.lang.Object>
[e[1;31mERRORe[m]   reason: inferred type does not conform to equality constraint(s)

That’s because IntelliJ is not perfect. The problem is that root.get(InfoPersonAddress.FIELD_NAME_CREATED_WHEN) uses the method <X> Path<X> get(String) and it tries to infer the attribute type based on the context in where the method is used. Since the context is criteriaBuilder.least which requires Expression<? extends Comparable>, the type inference fails with the Java compiler. To resolve this, provide type arguments, e.g. root.<Instant>get(InfoPersonAddress.FIELD_NAME_CREATED_WHEN)

THANK YOU!

Was totally confused there. It was Eclipse actually (but yeah, far from perfect).

Never seen that syntax, but it got past the error finally. (Let’s hope it works as expected.)