gpt4 book ai didi

java - CriteriaQuery selectDistinct 与 @EmbeddedId 生成无效 SQL

转载 作者:行者123 更新时间:2023-11-30 05:45:08 25 4
gpt4 key购买 nike

我有一个 CriteriaQuery 我正在构建需要获取行数的位置,但是当我使用 @EmbeddedId 定义复合键时,我收到错误当 Hibernate 尝试运行 SQL 时从数据库中获取:

14:35:16,356 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost/127.0.0.1:8080-2) SQL Error: 909, SQLState: 42000
14:35:16,357 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost/127.0.0.1:8080-2) ORA-00909: invalid number of arguments

Hibernate生成的SQL类似于下面的SQL,其中嵌入ID的成员位于distinct子句中:

select
count(distinct tab_.COLUMN_A,
tab_.COLUMN_B,
tab_.COLUMN_C) as col_0_0_
from
SOME_TABLE tab_
where
-- ...

我的 Java 代码的缩短版本是:

CriteriaBuilder builder = entityManager.getCriteriaBuilder();

CriteriaQuery<Long> countQuery = builder.createQuery(Long.class);
Root<SomeEntity> root = query.from(SomeEntity.class);
countQuery.select(builder.countDistinct(root));

// ... then add predicates

long totalRowCount = entityManager.createQuery(countQuery).getSingleResult();

是否有不同的(正确的)方法来使用带有 @EmbeddedId 的实体来获取计数?

最佳答案

这似乎是 Hibernate 中的一个已知问题。 https://hibernate.atlassian.net/browse/HHH-9814

关于java - CriteriaQuery selectDistinct 与 @EmbeddedId 生成无效 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54992747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com