You didn't post which errors do you receive, so I have to guess.
CriteriaBuilder.max accepts Expression<N>
where N extends Number
At the same time Root.get by default returns Path<Object>
which is inconvertible to Expression<Number>
.
So to make your call to max
work you need to specify generic parameter to root.get
:
cq1.select(cb1.max(root.<Number>get("relationId")));
here you can replace Number
with an actual type of relationId
(Long
, BigInteger
etc.)
UPDATE: @perissf addressed another issue with your code. If you are going to select maximal value (which is numeric) you should declare your CriteriaQuery
as a query to Number
not ElementRelationTypes