I am having following sql that needs to be transitioned to JPA specs:
select
* from TableA a
cross join TableB b
cross join (
select distinct refAId from TableC c where c.name like 'Your_NAME'
) as T
where
T.refAId = a.id
How can I form the cross join T to the root TableA here in terms of entities? So basically in the specification implementation I get CriteriaBuilder as Root root, CriteriaQuery<?> cq, CriteriaBuilder cb. Now how should i proceed ahead to map the root to the Query defined table T mentioned above?
Above query very efficient than the following:
select
* from TableA a
cross join TableB b
where
a.id in (
select refAId from TableC c where c.name like 'Your_NAME'
)
Why it is more efficient because the scan c.name like 'Your_NAME' happenes only once in the first query.