JPA+postgres: sum() operator applied to NumberExpression<Long> fails due to ClassCastException #636

Closed
alexeev opened this Issue Jan 21, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@alexeev

alexeev commented Jan 21, 2014

There is an issue when summarizing Long/BIGINT values in postgres.

According to postgres-documentation, aggregate function sum(BIGINT) returns NUMERIC. The return value is then converted to the java type BigDecimal and results in ClassCastException, because the expected return type is still Long.

Moreover, forcing numeric cast of the NumberExpression to Long.class is not possible, because the expression IS already of type Long. See NumberExpression.java:

castToNum(Class<A> type) {
    if (type.equals(getType())) {
        return (NumberExpression<A>) this; // <-- no way to enforce numeric cast to counter implicit cast by DBMS! 
    } else {
    return NumberOperation.create(type, Ops.NUMCAST, mixin, ConstantImpl.create(type));
    }
}

Tested with
querydsl 3.3.0,
eclipselink 2.4.2,
postgres 9.2.

timowest added a commit that referenced this issue Jan 22, 2014

timowest added a commit that referenced this issue Jan 27, 2014

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jan 27, 2014

Member

Could you try again with the latest SNAPSHOT from here: https://oss.sonatype.org/content/repositories/snapshots/

Member

timowest commented Jan 27, 2014

Could you try again with the latest SNAPSHOT from here: https://oss.sonatype.org/content/repositories/snapshots/

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 8, 2014

Member

Released in 3.3.1

Member

timowest commented Feb 8, 2014

Released in 3.3.1

@timowest timowest closed this Feb 8, 2014

@timowest timowest added this to the 3.3.1 milestone Apr 13, 2014

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