Java Criteriabuilder groupBy with Expression and Criteriabuilder.Function

Asked

Viewed 20 times

0

I’m getting the bug:

"ERROR: "movement0_.date1" column must appear in the GROUP BY clause or be used in an aggregate function". Estou usando o seguinte código para montagem da typedQuery:

Expression<String> groupExpression = cBuilder.function(
                        "TO_CHAR",
                        String.class,root.<LocalDate>get("date1"), 
                        cBuilder.literal("YYYY-MM"));
        cQuery.select( cBuilder.construct(MyDTO.class,
                    groupExpression,
                    cBuilder.count(root),
                    cBuilder.sum(root.<BigDecimal>get("value1")),
                    cBuilder.sum(root.<BigDecimal>get("value2")),
                    cBuilder.sum(root.<BigDecimal>get("value3")),
                    cBuilder.sum(root.<BigDecimal>get("value4"))
                )
            )
        .groupBy(groupExpression)
        .orderBy(groupExpression);

How to make a groupBy using CriteriaBuilder.function, as in the case above where I used the function TO_CHAR postgresql?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.