Repository: querydsl/querydsl

Issue #2326: Use of Hibernate 5.3 and HibernateQuery results in "Could not locate named parameter"
Created: 2018-06-22T21:01:58Z
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:
#2283 (comment)
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.

Duplicate issue #2411: querydsl-jpa HibernateQuery in hibernate 5.4.0.Final not working
Created: 2019-02-01T21:10:14Z
When I make a filter with HibernateQuery the applciation throw the exception IllegalArgumentException.
java.lang.IllegalArgumentException: Could not locate named parameter [3], expecting one of []
at org.hibernate.query.internal.ParameterMetadataImpl.getNamedParameterDescriptor(ParameterMetadataImpl.java:218) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.query.internal.ParameterMetadataImpl.getQueryParameter(ParameterMetadataImpl.java:187) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.query.internal.QueryParameterBindingsImpl.getBinding(QueryParameterBindingsImpl.java:188) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:497) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:110) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at com.querydsl.jpa.hibernate.HibernateUtil.setValue(HibernateUtil.java:91) ~[querydsl-jpa-4.1.4.jar:na]
at com.querydsl.jpa.hibernate.HibernateUtil.setConstants(HibernateUtil.java:79) ~[querydsl-jpa-4.1.4.jar:na]

In HibernateUtil, on method setValue(Query query, String key, Object val), on the else clouse have a query.setParameter(key, val). Same method in JPA have parse de key to Integer.

hQuery.select(Projections.fields(TotalPorAnoProjection.class,
                        debito.ano,
                        TOTAL_DEVIDO.sum().as("vlTotal")))
                .where(DebitoRepresentation.getVencidoCriteria(vencido),
                        ano != null ? debito.ano.eq(ano) : debito.ano.isNotNull(),
                        debito.situacao.eq(SituacaoParcela.ABERTO),
                        DebitoRepresentation.getFormaPagamentoCriteria())
                .groupBy(debito.ano)
                .orderBy(debito.ano.desc())
                .fetch();

Closing comment (2019-03-23T16:49:01Z): Seems to duplicate #2326