I do not know how to make a JAP criteria request end in a logical output.
The goal is to have a criteria query that looks like Oracle shows:
select 1 from dual where exists ( ... );
The where exists (...) that I did with the subquery, I am struggling with an external query.
And the practical use of this is to determine if this subquery is returned in an exists true or false clause.
Here is what I got:
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery<Object> query = criteriaBuilder.createQuery(); query.from(Boolean.class); query.select(criteriaBuilder.literal(true)); Subquery<Location> subquery = query.subquery(Location.class); Root<Location> subRootEntity = subquery.from(Location.class); subquery.select(subRootEntity); Path<?> attributePath = subRootEntity.get("State"); Predicate predicate = criteriaBuilder.equal(attributePath, criteriaBuilder.literal("TX")); subquery.where(predicate); query.where(criteriaBuilder.exists(subquery)); TypedQuery<Object> typedQuery = em.createQuery(query);
But the last line is not responding: Boolean is not an entity. I think my problem is not knowing how to express "from" the part of the query, since the result will be 1 or 0, true or false, not the entity.
I know that I could get any object, and then check if the result list has size 1, but I'm trying to learn how to get the logical result correctly, to avoid the unnecessary task of extracting these columns, and also to learn how to do this.
Is this even possible?
Thanks! Eduardo
Edy bourne
source share