我有一个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
生成的SQL Hibernate类似于下面的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