这是我的代码:
@Entity
@Table("Books")
public class BookImp implements Book {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@ElementCollection
private Set<String> authors = new HashSet<String>();
// getters + constructors
}
我想创建一个 SQL 查询,它将返回最伟大作者集合的大小。我该怎么做?
编辑:对于那些建议使用 for 循环的人,我希望答案看起来像这样:
@Override
public int getLargestAuthors() {
return entityManager.createQuery("select b.authors from BookImpl b where b.authors.size ...").getSingleResult().size();
}
最佳答案
不是 mysql 向导,但你不能这样做吗?
select MAX(b.authors.size) from BookImpl b
关于java - 如何返回 JPA 中最大 Collection 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25581219/