JPA, JPQL, GROUP BY and SUM - The argument must be numeric! by @MatthiasReining

Integer vs. int / EclipseLink on GF4

JPA, JPQL, GROUP BY and SUM - The argument must be numeric!

I got following error for one of my JPA queries on GF4 with EclipseLink:

Exception Description: Error encountered when building the @NamedQuery [AccountingTimeDetail#groupByTitleAndUser] from entity class [class org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata].
Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.jpa.jpql.parser.NullExpression cannot be cast to org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable

Netbeans gave me a more friendly message, but still an error message...

AccountingTimeDetail#groupByTitleAndUser[46;61]: The argument must be numeric.

This was a little bit strange for me on the first view. My entity beans looks quite good.

@Entity
@NamedQueries({
    @NamedQuery(name = AccountingTimeDetail.groupByTitleAndUser,
            query = "SELECT pm.title, atd.user, atd.priceHour, SUM(atd.workingTime) FROM AccountingTimeDetail atd, ProjectMember pm WHERE atd.user = pm.individual AND atd.accountingPeriod = :AccountingTimeDetailqueryParam_accountingPeriod GROUP BY pm.title, atd.user, atd.priceHour"
    )})
public class AccountingTimeDetail implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String groupByTitleAndUser = "AccountingTimeDetail#groupByTitleAndUser";
    public static final String queryParam_accountingPeriod = "accountingPeriod";

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private Integer workingTime;

    ...

Normally I would say a simple JOIN with a GROUP BY clause. But SUM caused the problem in this case.

SUM can only be used for numeric values! All right!

But in this case Integer is not a numeric value!

Changing my attribute workingTime from Integer to int everything works fine!!!

Nevertheless, it's strange and it's wrong!

See the Oracle documentation:

Name: SUM
Return Type: Long (for integral fields), Double (for floating-point fields), BigInteger (for BigInteger fields), BigDecimal (for BigDecimal fields)

When I use BigDecimal as attribute type, I get on GF4 the described error! Bad thing!






Google