Use of Hibernate 5.3 and HibernateQuery results in "Could not locate named parameter"
See original GitHub issueThe use of querydsl-jpa’s HibernateQuery with Hibernate 5.3 will thrown an exception when you use parameters:
java.lang.IllegalArgumentException: Could not locate named parameter [1], expecting one of []
at org.hibernate.query.internal.ParameterMetadataImpl.getNamedParameterDescriptor(ParameterMetadataImpl.java:218)
at org.hibernate.query.internal.ParameterMetadataImpl.getQueryParameter(ParameterMetadataImpl.java:187)
at org.hibernate.query.internal.QueryParameterBindingsImpl.getBinding(QueryParameterBindingsImpl.java:188)
at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:494)
at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:107)
at com.querydsl.jpa.hibernate.HibernateUtil.setValue(HibernateUtil.java:91)
at com.querydsl.jpa.hibernate.HibernateUtil.setConstants(HibernateUtil.java:79)
at com.querydsl.jpa.hibernate.AbstractHibernateQuery.createQuery(AbstractHibernateQuery.java:105)
at com.querydsl.jpa.hibernate.AbstractHibernateQuery.createQuery(AbstractHibernateQuery.java:97)
at com.querydsl.jpa.hibernate.AbstractHibernateQuery.fetch(AbstractHibernateQuery.java:174)
at com.querydsl.example.jpa.repository.TweetRepository.findAllWithHibernateQuery(TweetRepository.java:30)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:66)
at com.querydsl.example.jpa.repository.TweetRepositoryTest.find_list_by_predicate(TweetRepositoryTest.java:44)
I am not the only person experiencing this error, as @jpimag experienced the same issue: https://github.com/querydsl/querydsl/pull/2283#issuecomment-399247423
To reproduce this issue, I modified the querydsl-example-jpa-guice example contained within the QueryDSL repository. You can find the patch here:
https://gist.github.com/andygoossens/5eed865ccfe84857f7e99ddb2dfb5790
Then just run test class com.querydsl.example.jpa.repository.TweetRepositoryTest
and check whether it fails.
You can easily compare the different behaviour between Hibernate versions by altering the <hibernate.version>
parameter in the POM file (part of the “hibernate5” profile). e.g. Hibernate version 5.2.17.Final works fine, but version 5.3.1.Final fails. Don’t forget to activate the necessary Maven profile(s) of course! 😃
It looks like there is a mixup between named query parameters and positional query parameters. getConstantToLabel()
could contain a constant with index “1” (as a String and meant to be used as ?1
) but QueryDSL is calling Query<R> setParameter(String name, Object val);
meant for named parameters (like :example
). Hibernate does not find the named parameter “1” and fails.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:14 (7 by maintainers)
What’s going on with this? Is there going to be a new querydsl release with 5.3.x compatibility? I was originally waiting for the fix for hibernate 5.2 … now 5.3 is out … is there a plan? Querydsl is starting to feel a bit neglected … is the idea to keep it alive and up to date on your part? Thanks!
@Shredder121 is there anything we can do to help sorting this out? QueryDSL is such an useful framework! But I’m affraid that for Spring Boot users (v >=2.1), Hibernate 5.3 support is a must! Thank you