Re: Problem with BigDecimal comparison in JPAQuery

1,015 views
Skip to first unread message

Timo Westkämper

unread,
Sep 13, 2012, 2:17:22 AM9/13/12
to Querydsl on behalf of Ken Hill
Hi.

This looks like a bug. Could you create a ticket for it on GitHub?

Br,
Timo Westkämper

On Thu, Sep 13, 2012 at 12:00 AM, Querydsl on behalf of Ken Hill <querydsl+noreply-APn2wQc8P9YmgxA...@googlegroups.com> wrote:
I am encountering a problem when trying to do a comparison on a NumberPath<BigDecimal> 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<BigDecimal> 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<Double>?) it executes just fine.

I am lucky in that I happen to have this BigDecimal in the DB so I can do 3 or 4 joins and grab it, but it adds a fair bit of overhead that seems unnecessary. This is a contrived example, in the real use case I am calculating a percentage and comparing to a fixed threshold (ABS(bigd1 - bigd2) / bigd1) * 100) > threshold).

Env:
QueryDSL 2.7.0
JPA2
Maven entity generation

Thanks for your help!



--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com



Ken Hill

unread,
Sep 13, 2012, 8:33:47 AM9/13/12
to quer...@googlegroups.com
Entered. Issue #228.

Thanks,
Ken


On Thursday, September 13, 2012 2:17:23 AM UTC-4, Timo Westkämper wrote:
Hi.

This looks like a bug. Could you create a ticket for it on GitHub?

Br,
Timo Westkämper

Reply all
Reply to author
Forward
0 new messages