Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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
Hibernate jpql order by子查询产生意外的AST节点异常_Hibernate_Playframework_Jpql - Fatal编程技术网

Hibernate jpql order by子查询产生意外的AST节点异常

Hibernate jpql order by子查询产生意外的AST节点异常,hibernate,playframework,jpql,Hibernate,Playframework,Jpql,我将一个正在工作的(postgre)sql查询转换为jpql,但hibernate抛出了一个 org.hibernate.hql.ast.QuerySyntaxException: 意外的AST节点 例外情况 以下是我的核心模型类: @Entity public class Piece { @Id @GeneratedValue public Long id; @ManyToOne public AUser user; public long i

我将一个正在工作的(postgre)sql查询转换为jpql,但hibernate抛出了一个

org.hibernate.hql.ast.QuerySyntaxException: 意外的AST节点 例外情况

以下是我的核心模型类:

@Entity
public class Piece {
    @Id
    @GeneratedValue
    public Long id;

    @ManyToOne
    public AUser user;
    public long index;
...
}

@Entity
public class Vote {
    @Id
    @GeneratedValue
    public Long id;

    @ManyToOne
    public AUser receiver;
...
}

@Entity
public class AUser {
    @Id
    @GeneratedValue
    public Long id;

    @OneToMany(mappedBy="receiver", cascade=CascadeType.ALL)
    public List<Vote> receivedVotes;
...
}

谁能解释一下异常,为什么会发生,以及如何更改查询以避免它。谢谢

JPQL不支持按排序的子查询。如果我正确理解您的查询,您可以尝试以下操作:

select p 
from Piece p left join p.user.receivedVotes rv
group by p
order by count(rv) desc, p.index

非常感谢,你的建议做了一点小小的调整,效果非常好:我不得不在GROUPBY子句中添加“p.id,p.user.id,p.index”
select p 
from Piece p left join p.user.receivedVotes rv
group by p
order by count(rv) desc, p.index