我在 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
有人知道出了什么问题吗?
我通过SQ语句解决了这个问题,没有使用Criteria API。