SAP / olingo-jpa-processor-v4

The JPA Processor fills the gap between Olingo V4 and the database, by providing a mapping between JPA metadata and OData metadata, generating queries and supporting the entity manipulations.
Apache License 2.0
123 stars 76 forks source link

$count function is not working with with MS SQL server #145

Closed kumar842 closed 2 years ago

kumar842 commented 2 years ago

API http://localhost:8091/v1/Orders/$count http://localhost:8091/v1/Orders?$count=true

Error: { "error": { "code": null, "message": "class java.lang.Integer cannot be cast to class java.lang.Long" } }

In MS SQL server, the return type of the count function is int. Annotation 2022-02-21 200426

JPAJoinQuery.java > CountResults() method will be called in case of /orders/$count or /orders?$count=true. This calls getSingleResult() (line no: 104). So, expected return type is Long.

Annotation 2022-02-21 141828

TypeQueryImpl.java > getSingleResult() calls getResultList()(line no: 185), which returns List instead of List<Long)

Annotation 2022-02-21 143514

because the select count() query returns List. Annotation 2022-02-21 142036

Can you please help or guide here.

wog48 commented 2 years ago

Hello,

I have create a new version containing a correction.

At the end it was surprising that a an Integer is returned even so the corresponding CriteriaBuilder method indicates that count returns a Long: Expression<Long> countDistinct(Expression<?> x);

In case you still face a problem, reopen the issue.