4

The current code:

CriteriaQuery criteriaQuery = cb.createQuery(MinutisPreke.class);
Root<MinutisPreke> from = criteriaQuery.from(MinutisPreke.class);
Join<LankomumasDiena, MinutisPreke> ld = from.join("lankomumasDiena", JoinType.LEFT);
cb.and(cb.equal(ld.get("intervalas"), 7));

generates the following query:

SELECT COUNT(t0.pr_id) FROM preke AS t0 
LEFT OUTER JOIN lankomumas AS t1 
ON (t1.pr_id = t0.pr_id) 
WHERE (t1.intervalas = 7)

How to add statement in the LEFT OUTER JOIN ON clause using criteria query so my code would generate this query:

SELECT COUNT(t0.pr_id) FROM preke AS t0 
LEFT OUTER JOIN lankomumas AS t1 
ON (t1.pr_id = t0.pr_id) AND (t1.intervalas = 7)

EDIT 1: If you don't see any difference in first and second querys, please read this thread: SQL join: where clause vs. on clause

Community
  • 1
  • 1
Minutis
  • 1,193
  • 1
  • 17
  • 47

1 Answers1

2

EclipseLink added support for the ON clause in a 2.5 nightly build as described here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=367452 but it is not a part of the JPA specification so you will need to cast the Join to EclipseLink's org.eclipse.persistence.internal.jpa.querydef.JoinImpl

((JoinImpl)ld).on(cb.and(cb.equal(ld.get("intervalas"), 7));
Chris
  • 20,138
  • 2
  • 29
  • 43