У меня есть два объекта, файл и комментарий:Как заказать по количеству родственного лица
@Entity
@Table(name = "FILE")
@SuppressWarnings("serial")
@XmlRootElement
public class File implements Serializable {
(...)
private Set<Commentary> commentaries = new HashSet<Commentary>();
(...)
@OneToMany(mappedBy = "file")
public Set<Commentary> getCommentaries() {
return commentaries;
}
}
@Entity
@Table(name = "COMMENTARY")
@SuppressWarnings("serial")
public class Commentary implements Serializable {
(...)
private File file;
(...)
@ManyToOne
@JoinColumn(name = "FILE_ID")
public File getFile() {
return file;
}
Я хочу, чтобы сделать запрос HQL, чтобы получить файлы, заказав их по количеству комментариев каждый из них связаны. Я пробовал:
SELECT f FROM FILE f WHERE f.name LIKE '%example%' ORDER BY COUNT(f.commentaries)
не повезло. Как я могу сделать это правильно с помощью HQL?
Какая ошибка вы наблюдаете? –