I have a table called programs
and I want to create a query using CriteriaBuilder
that joins the table to itself as in:
SELECT *
FROM programs p1
LEFT JOIN programs p2
ON p1.name = p2.name AND p1.version < p2.version
So far I have
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Program> cq = cb.createQuery(Program.class);
Root<Program> root = cq.from(Program.class);
Join<Program, Program> programJoin = root.join("name", JoinType.LEFT);
programJoin.on(cb.equal(//I don't know...))
But I'm stuck here, not knowing how to recreate the above SQL ON
condition p1.version < p2.version