Fixed column value when using JPA, Criteria API and a static metamodel
-
27-05-2021 - |
Question
Given the following:
CriteriaQuery<SomeDTO> cQuery;
CriteriaBuilder cb;
Root<SomeClass> r;
...
cQuery.select(cb.construct(SomeDTO.class,
"FIXED VALUE",
r.get(SomeClass_.someValue)
));
Is there a way inwith the JPA criteria api and a static metamodel to create a select, which returns a fixed value for one column? The respective SQL should be something like
SELECT 'FIXED VALUE', someValue FROM someClassTable WHERE ...;
Thanks in advance!
Solution
The answer I was looking for is CriteriaBuilder.literal()
: http://docs.oracle.com/javaee/6/api/javax/persistence/criteria/CriteriaBuilder.html#literal%28T%29
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow