Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join condition leads to Hibernate QuerySyntaxException after Querydsl migration from 2.7.0 to 2.8.0 #250

Closed
Buttstedt opened this issue Oct 16, 2012 · 5 comments

Comments

@Buttstedt
Copy link

@Buttstedt Buttstedt commented Oct 16, 2012

We are using Hibernate 4.1.4 as persistence provider.
With Querydsl 2.7.0 the following example query which contains an additional join condition works fine:

JPAQuery query = new JPAQuery(entityManager);
query.from(cat)
.leftJoin(cat.kittens, kitten)
.with(kitten.bodyWeight.gt(10.0))
.list(cat);

Querydsl 2.7.0 generates following JPQL:
select from Cat as cat
left join cat.kittens as kitten
with kitten.bodyWeight > 10.0

Querydsl 2.8.0 generates following JPQL:
select from Cat as cat
left join cat.kittens as kitten
on kitten.bodyWeight > 10.0

and leads to Hibernate QuerySyntaxException:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: on

This seems to be a bug, because the keyword "on" is not part of JPQL specification (JPA 2.0).

timowest added a commit that referenced this issue Oct 16, 2012
@timowest
Copy link
Member

@timowest timowest commented Oct 16, 2012

There is no "on" and "with" in JPA 2.0, but there is "on" in JPA 2.1 http://stackoverflow.com/questions/11100702/how-to-have-multiple-conditions-in-jpql-join

Is this the constructor you use for query creation?

JPAQuery query = new JPAQuery(entityManager);

Querydsl should successfully detect the JPQL dialect to use based on the entity manager, but maybe this fails here. Querydsl uses "with" for Hibernate and "on" for everything else.

Which container (Spring, Guice etc) are you using?

@Buttstedt
Copy link
Author

@Buttstedt Buttstedt commented Oct 16, 2012

Yes, I am using the constructor

JPAQuery query = new JPAQuery(entityManager);

I am working with GlassFish 2.1.1 (with migration to JPA 2.0)

You are right, it seems to be a problem with the dialect detection:
When using the Hibernate stand-alone EntityManager without any EJB container I am getting "with" with Querydsl 2.8.0.

@timowest
Copy link
Member

@timowest timowest commented Oct 16, 2012

What does entityManager.getDelegate() return when JPA is managed by GlassFish? Querydsl expects a org.hibernate.Session instance.

@Buttstedt
Copy link
Author

@Buttstedt Buttstedt commented Oct 17, 2012

For GlassFish entityManager.getDelegate() returns the instance org.hibernate.ejb.EntityManagerImpl.

In case of Hibernate stand-alone EntityManager (without GlassFish EJB container) getDelegate() returns the instance org.hibernate.internal.SessionImpl.

timowest added a commit that referenced this issue Oct 17, 2012
@timowest
Copy link
Member

@timowest timowest commented Oct 19, 2012

Released in 2.8.1

@timowest timowest closed this Oct 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants