Hibernate,hql,count with join fetch生成select with all fields and count,为什么?
我有这样一个hql查询:Hibernate,hql,count with join fetch生成select with all fields and count,为什么?,hibernate,jpql,Hibernate,Jpql,我有这样一个hql查询: return (long)Session.CreateQuery (" select count(*) " + " from Files p " + " join fetch p.Application a " + " where
return (long)Session.CreateQuery (" select count(*) " +
" from Files p " +
" join fetch p.Application a " +
" where a.Name = :AppName")
.SetParameter("AppName", application)
.UniqueResult();
select field1, field2, field3, count(*)
Hibernate创建如下sql查询:
return (long)Session.CreateQuery (" select count(*) " +
" from Files p " +
" join fetch p.Application a " +
" where a.Name = :AppName")
.SetParameter("AppName", application)
.UniqueResult();
select field1, field2, field3, count(*)
这就是为什么它不能被执行
为什么选择count(*)使hibernate列出所有字段,以及如何防止它
感谢在我看来,问题在于使用“
FETCH
”,它通常用于从数据库中获取给定实体的依赖项。所以Hibernate查询应用程序的字段来创建对象
如果只想计算与应用程序关联的文件,请将“内部联接”
”更改为“联接获取”
”(或简单地更改为“联接”
)。唯一查询的字段应该是count(*)
then