If you have some kind of following structure:
Class EntityA
--------
long Id
Set<EntityB> Bs
Class EntityB
-------
long Id
EntityA A
I think following should work
SELECT a FROM EntityA a WHERE a.Bs IS EMPTY
Frage
I have for example 2 entities.
A entity (Mysql Table name="A")
B entity (Mysql Table name="B")
I want fetch data from A table where it is not in the B table.
I wrote sql and it is working.
SELECT * FROM A
LEFT OUTER JOIN B
ON A.id = B.a_id
WHERE B.id IS null
How to realize it with JPQL?
Lösung
If you have some kind of following structure:
Class EntityA
--------
long Id
Set<EntityB> Bs
Class EntityB
-------
long Id
EntityA A
I think following should work
SELECT a FROM EntityA a WHERE a.Bs IS EMPTY
Andere Tipps
See the following website..It will help you
You may use this command
SELECT * FROM A WHERE A.id NOT IN (SELECT B.id FROM B)
If you wan to use only join let me know
I believe the following should work:
SELECT A FROM A a LEFT JOIN a.B b WHERE b.id = null;
This should join A with B on id leaving null where A can not match with B. Then it selects the rows from A where b.id is null. Seems like what you're looking for. Also checkout the following SOs: How to make a JPA query with LEFT OUTER JOIN And as done in the following: How to create a JPA query with LEFT OUTER JOIN
Let me know whether it worked out.