1

I want to run a sql:

select b.* from A a inner join B b on a.c = b.c where b.status = 1 ; 

now I have to do this use Jpa CriteriaQuery, and I hava got ( Root<A> root ), A and B has no PK & FK, columu c is the FK of A and B, so how to do?

    CriteriaQuery aQuery= cb.createQuery(A.class);
    Root<A> aRoot = aQuery.from(A.class);

then how to do ?

1 Answers1

0

Firstly, JPQL does not allow joining to arbitrary other root objects, so you can't do that in JPQL; only allowing you to join along relations. Secondly Criteria simply supports what JPQL supports, so you cannot do that in Criteria either.

The closest is to have a second root and a CROSS JOIN between them, or use vendor extensions (but the Criteria API will likely not allow such a vendor extensions since its API is fixed, so you'd likely have to use string-bsed JPQL instead).