Exception with BigDecimal constant in JPAQuery creation #228

Closed
steeltomato opened this Issue Sep 13, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@steeltomato

Encountered a problem when trying to do a comparison on a NumberPath after doing math on it in a JPAQuery. For example:

...where(bigd1.divide(bigd2).loe( new BigDecimal("1.00") ))

with bigd1 and bigd2 both being NumberPath paths, results in this trace:

java.lang.IllegalArgumentException: Parameter value [1.0] did not match expected type [java.math.BigDecimal]
at org.hibernate.ejb.AbstractQueryImpl.validateParameterBinding(AbstractQueryImpl.java:370) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:343) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:370) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:437) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:67) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at com.mysema.query.jpa.impl.JPAUtil.setConstants(JPAUtil.java:44) [querydsl-jpa-2.7.0.jar:]
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:136) [querydsl-jpa-2.7.0.jar:]
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:104) [querydsl-jpa-2.7.0.jar:]
at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:272) [querydsl-jpa-2.7.0.jar:]

However, without the divide (which happens to return a NumberExpression) it executes just fine.

Assuming this was a type coercion problem, I tried to cast the BigDecimal paths to Double.class (castToNum) but this causes additional exceptions:

java.lang.IllegalArgumentException: Got no pattern for CAST
at com.mysema.query.support.SerializerBase.visitOperation(SerializerBase.java:318) [querydsl-core-2.7.0.jar:]
at com.mysema.query.jpa.JPQLSerializer.visitOperation(JPQLSerializer.java:368) [querydsl-jpa-2.7.0.jar:]
at com.mysema.query.jpa.JPQLSerializer.visitNumCast(JPQLSerializer.java:377) [querydsl-jpa-2.7.0.jar:]

Environment:
QueryDSL 2.7.0
Mvn entity generation using plugin
JPA2 wrapping Hibernate 4.0.1 against a SQL Server 2012 datasource

timowest added a commit that referenced this issue Sep 15, 2012

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 29, 2012

Member

Released in 2.8.0

Member

timowest commented Sep 29, 2012

Released in 2.8.0

@timowest timowest closed this Sep 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment