带有 H2 和 GROUP BY 子句的 Criteria API

问题描述 投票:0回答:1

我在 Spring Boot 测试中使用 H2 数据库。它测试使用以下条件查询的函数:

        query
                .multiselect(
                        tenant,
                        cb.count(root)
                )
                .where(cb.and(
                    statusIsEqual,
                    lifeSpanNotNull,
                    lifespanGtZero,
                    notExpired
                ))
                .groupBy(tenant);

当我运行测试时,出现以下错误:

“P1_0.TENANT_APP_ID”列必须在 GROUP BY 列表中; SQL语句:

select p1_0.tenant_app_id, count(p1_0.id)
from push_notification p1_0
where p1_0.status = ?
  and p1_0.lifespan is not null and p1_0.lifespan > ?
  and current_date <= p1_0.expiry_date
group by 1

有人知道出了什么问题吗?

sql group-by h2 criteria-api
1个回答
0
投票

我通过SQ语句解决了这个问题,没有使用Criteria API。

© www.soinside.com 2019 - 2024. All rights reserved.