2
我翻译工作(postgre)SQL查询来JPQL,但冬眠抛出一个由子查询JPQL顺序产生意外AST节点例外
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查询:
String query = "select p from Piece p order by (select count(v.receiver) from Vote v where v.receiver.id=p.user.id) desc, p.index";
任何人都可以解释异常,为什么会发生以及如何更改查询以避免它。谢谢!
非常感谢,您的建议有轻微的调整工作很大:我不得不添加“p.id,p.user.id页。索引“到group by子句 – maxmc 2011-04-05 12:54:53