10

I want to join two tables using JPQL:

SELECT * FROM A LEFT JOIN 
B ON A.ID = B.A_ID AND B.lng = 'en'

The important part is AND B.lng = 'en'

Is this possible in JPQL?

Hash
  • 4,647
  • 5
  • 21
  • 39
Jeremy S.
  • 6,423
  • 13
  • 48
  • 67
  • Have you resolved this? I have a similar issue, posted [here][1]. [1]: http://stackoverflow.com/questions/28633921/atypic-jpa-onetoone-relation – Ronye Vernaes Feb 20 '15 at 17:01
  • It works in SQL but can't convert it into JPQL. Adding `AND B.lng = 'en'` condition in **ON** condition list is still not possible using JPQL. – Mr ASquare May 31 '17 at 10:08

2 Answers2

9

JPA 2.0 does not support an ON clause, but the JPA 2.1 draft does.

EclipseLink 2.4 supports an ON clause.

See, http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#ON

James
  • 17,965
  • 11
  • 91
  • 146
  • 6
    HQL supports it using the `with` keyword: `select a from A a left join a.b b with b.language = 'en'` – JB Nizet Jun 19 '12 at 17:10
1

Yes it is possible, there is a similar question here. However, if your entities are mapped, you should be able to access them in a query.

Community
  • 1
  • 1
John Kane
  • 4,383
  • 1
  • 24
  • 42