2

I'm having a unexpected problem to perform a query using QueryDsl/Hibernate (2.8.2).

My field is generated like this, as you can see, it's an Integer.

public final NumberPath nbPotatoes= createNumber("nbPotatoes", Integer.class);

I'm trying to add the "having" clause to my request like this:

 res.having( (QGarden.garden.nbPotatoes.sum()).gt(0) ); 

I'm performing a sum on the nbPotatoes field and selecting only rows which have a sum greater than zero.

When the request is executed, I'm getting the following exception:

Caused by: java.lang.IllegalArgumentException: Parameter value [0] did not match expected type [java.lang.Long]
    at org.hibernate.ejb.AbstractQueryImpl.validateParameterBinding(AbstractQueryImpl.java:375)
    at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:348)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:375)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:442)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:72)
    at com.mysema.query.jpa.impl.JPAUtil.setConstants(JPAUtil.java:44)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:135)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:103)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:271)

So I tried to cast my parameter to a Long, but it didn't work and I'm getting the same exception. The only way I find was to change the type of the field to Long instead of Integer, but I'm not very happy with this solution...

Any idea where the bug could be or if I'm doing something wrong ?

Thanks !

edit 1: Unfortunately, it still does not work with QueryDsl 3.2.0. I have debugged some portions of code and it seems that Hibernate is doing something wrong. My parameter value is obviously an Integer (I changed the value to 748 to be sure I get the right parameter). But after calling the method "getNamedParameterExpectedType", the determined type is evaluated as Long ?! Then, when Hibernate is checking the parameter binding, it raises an matching Exception as it expected a Long type.

http://www.images-host.fr/view.php?img=14062708bug-hibernate.png

No one came accross this issue and solved it ?

Arthur H
  • 46
  • 5

0 Answers0