I am using JPA CriteriaBuilder
to create query and uses constructor base selection. But In my case I want some default value to specific parameter (Dummy). But that parameter is not a table column.
Is there any way to achieve this?
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<HEntity> cq = cb.createQuery(HEntity.class);
Root<HTable> root = cq.from(HTable.class);
// original selection criteria
// build result set class
cq.select(cb.construct(HDto.class,
root.<Long>get("id"),
root.<Date>get("datetime"),
root.get("device")
)
Is there any way to achieve like following?
// build result set class
cq.select(cb.construct(HDto.class,
root.<Long>get("id"),
root.<Date>get("datetime"),
root.get("devicename"),
"default value"
)
Expression<String> localExp = cb.literal("My String");
Please check below Oracle Doc link http://docs.oracle.com/javaee/6/api/javax/persistence/criteria/CriteriaBuilder.html#literal(T)