Search code examples
querydslduration

Querydsl - Sum with type Duration


I have a Entity that have a Duration type field and I would like to sum this field with QueryDsl. Is it possible? I was search on querydsl.com and dont find a solution.

The sum accepts only number, but my field is Duration type.

public static <E extends Number> AbstractGroupExpression<E,E> sum(Expression<E> expression)

Any sugestions, please?


Solution

  • Even I was facing the same issue. I resolved it by using Expressions.numberPath() as below.

    final NumberPath<Long> durationPathAsLongPath = Expressions.numberPath(Long.class, durationPath.getMetadata());
    

    Then you can use sum() on the resulting NumberPath.