question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of Hibernate 5.3 and HibernateQuery results in "Could not locate named parameter"

See original GitHub issue

The 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:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
m4urercommented, Sep 28, 2018

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!

8reactions
jfcabralcommented, Mar 23, 2019

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

could not locate named parameter [templateId] - Stack Overflow
Your parameter name is id not templateId . You have to Change to: String hql ="from FieldTemplate where templateId= :id"; Query query =...
Read more >
QueryParameterException could not locate named parameter
I have a native SQL query which execute through Hibernate. Thanks in advance for any help.
Read more >
Hibernate 5.3 Migration Guide - OpenbravoWiki
The org.hibernate.query.Query.getNamedParameters() method which returns an array containing the names of the named parameters used in a query is also ...
Read more >
Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Hibernate may not be the best solution for data-centric applications that only use ... Use Hibernate and report any bugs or issues you...
Read more >
Intermittent Error: Parameter does not exist as a named ...
The problem goes away after restarting the Web Logic instance. We use Native SQL with Named Parameters. Database is Oracle 12c. Application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found