Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql hql查询中的Hibernate计数一对多关联?_Postgresql_Hibernate - Fatal编程技术网

Postgresql hql查询中的Hibernate计数一对多关联?

Postgresql hql查询中的Hibernate计数一对多关联?,postgresql,hibernate,Postgresql,Hibernate,一篇文章有许多喜欢的 我正在尝试创建一个hql查询,该查询计算(count(article.upvoces))一篇文章的投票数 下面列出了我尝试的查询。我没有费心添加我的整个类-所有必需的代码如下 class Article { ... ... @OneToMany(mappedBy = "article", fetch = FetchType.LAZY) private Set<Like> articleLikes; // Contains uId who liked + art

一篇文章有许多喜欢的

我正在尝试创建一个hql查询,该查询计算(count(article.upvoces))一篇文章的投票数

下面列出了我尝试的查询。我没有费心添加我的整个类-所有必需的代码如下

class Article {
...
... 
@OneToMany(mappedBy = "article", fetch = FetchType.LAZY)
private Set<Like> articleLikes; // Contains uId who liked + articleId

select a, count(a.articleLikes) from Article a

我做错了什么

您应该选择特定的文章行。。选择一个,将不会给出任何特定行

你应该先得到这篇文章,然后再把a.articleLikes的大小作为一个集合

select a.articleLikes from Article a where YOUR-FINDER 
然后得到尺寸

或者


从like中选择count(*),其中……

数据库表中没有属性articleLikes的映射列

对日志使用hibernate.show\u sql属性

select a.articleLikes from Article a where YOUR-FINDER