Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alexeev opened this issue Jan 21, 2014 · 2 comments
Labels
Milestone

Comments

@alexeev
Copy link

@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
Copy link
Member

@timowest timowest commented Jan 27, 2014

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

@timowest
Copy link
Member

@timowest 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
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants