I translated a working (postgre)sql query to jpql, but hibernate throws a
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node exception
These are my core model classes:
@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;
...
}
Here is my jpql query:
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";
Can anyone explain the exception, why it happens and how to change the query to avoid it. Thanks!