Hibernate jpql order by子查询产生意外的AST节点异常
我将一个正在工作的(postgre)sql查询转换为jpql,但hibernate抛出了一个 org.hibernate.hql.ast.QuerySyntaxException: 意外的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
@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