Re: QueryDSL JPA left outer join between 2 entities without relation

4,854 views
Skip to first unread message

Timo Westkämper

unread,
Nov 12, 2012, 4:15:03 AM11/12/12
to quer...@googlegroups.com
Hi.

How do you create your query? It appears that for some reason your query isn't serialized properly. Hibernate uses with instead of on.

But the central problem is that JPQL doesn't support joins between top level variables. You need to express it in a different way, e.g. subqueries, if you only need constraints.

Br,
Timo

On Monday, November 12, 2012 11:09:07 AM UTC+2, Georgian Micsa wrote:
Hi,


I have 2 entitites, let's say A and B and there is no relation between them.
I want a query that left outer joins them on the id, so I tried the following:

query.from(A).leftJoin(B).with(A.id.eq(B.id));

The generated JPQL looks like this:
  from A a
       left join B b on b.id = a.id

and there is the following exception:

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: on near line ...

Is it possible to do this in QueryDSL or JPQL (the on seems not to be a valid JPQL keyword).
We are using Hibernate 4.1.7 and querydsl 2.8.0.

Thanks,
Georgian

Georgian Micsa

unread,
Nov 12, 2012, 4:37:39 AM11/12/12
to quer...@googlegroups.com
Hi,

We are using JPA 2.0 on top of Hibernate:

new JPAQuery(entityManager, JPQLTemplates.DEFAULT)

Timo Westkämper

unread,
Nov 12, 2012, 4:42:21 AM11/12/12
to Querydsl on behalf of Georgian Micsa
Hi.

Try it without the second constructor argument, JPQLTemplates.DEFAULT gives you standard JPQL serialization which is not fully compatible with Hibernate.

new JPAQuery(entityManager)

will use autodetection of the JPA dialect and will pick HQLTemplates.DEFAULT instead internally.

But that still leaves you with the second problem.

Br,
Timo
--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com



Georgian Micsa

unread,
Nov 12, 2012, 5:45:26 AM11/12/12
to quer...@googlegroups.com
Hi,

I did what you said, now the generated query contains "with" but there is still the left outer join problem of entities unassociated like you said.

Thanks


On Monday, November 12, 2012 10:42:22 AM UTC+1, Timo Westkämper wrote:
Hi.

Try it without the second constructor argument, JPQLTemplates.DEFAULT gives you standard JPQL serialization which is not fully compatible with Hibernate.

new JPAQuery(entityManager)

will use autodetection of the JPA dialect and will pick HQLTemplates.DEFAULT instead internally.

But that still leaves you with the second problem.

Br,
Timo

Timo Westkämper

unread,
Nov 12, 2012, 5:48:33 AM11/12/12
to Querydsl on behalf of Georgian Micsa
Hi.

Yes, like I said, you can't express this with a left join. You can either declare both in the from part (cross join), or use a subquery.

Timo

ajay tiℓe

unread,
Oct 11, 2013, 3:04:51 AM10/11/13
to quer...@googlegroups.com
Hi All,
 
Got this thread usefull but ,i want same iffect that all records of left table and matching of right one using subquery ...would any one write query for me.
 
Nitin.
 

On Monday, 12 November 2012 16:18:34 UTC+5:30, timowest wrote:
Hi.

Yes, like I said, you can't express this with a left join. You can either declare both in the from part (cross join), or use a subquery.

Timo

Reply all
Reply to author
Forward
0 new messages