Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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
Java 如何按相关实体的计数进行订购_Java_Hibernate_Sql Order By_Hql - Fatal编程技术网

Java 如何按相关实体的计数进行订购

Java 如何按相关实体的计数进行订购,java,hibernate,sql-order-by,hql,Java,Hibernate,Sql Order By,Hql,我有两个实体,文件和评论: @Entity @Table(name = "FILE") @SuppressWarnings("serial") @XmlRootElement public class File implements Serializable { (...) private Set<Commentary> commentaries = new HashSet<Commentary>(); (...) @OneToMany

我有两个实体,文件和评论:

@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(commentaries)

我找到了答案。正确的HQL查询是:

SELECT f FROM FILE f WHERE f.name LIKE '%example%' ORDER BY size(f.commentaries)

你观察到了什么错误?
SELECT f FROM FILE f WHERE f.name LIKE '%example%' ORDER BY size(f.commentaries)