I have 2 tables - TableA and TableB for example with some data in them as defined in this post - How to join results of 2 tables based on not condition
Now I am plan
You need to use a theta-style join:
select b, a
from TableB b, TableA a
where not exists (
select 1
from TableB b1, TableA a1
where
b1.partNumber = a1.partNumber and
b1.id = b.id and
a1.id = a.id
)
order by b.id
or you can use an SQL query to fetch entities as well:
List result = session.createSQLQuery("SELECT b.*, c.* \n" +
"FROM TableB b AS t\n" +
"CROSS JOIN (SELECT id AS Aid, name AS Aname, partNumber AS Apart\n" +
" FROM TableA AS a\n" +
" WHERE NOT EXISTS (SELECT 1\n" +
" FROM TableB AS b\n" +
" WHERE b.partNumber = a.partNumber)) AS c\n" +
"ORDER BY b.id ")
.addEntity("b", B.class)
.addEntity("a", A.class)
.list();