【发布时间】:2014-10-24 05:30:25
【问题描述】:
这是我的代码:
@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();
}
【问题讨论】:
标签: java jpa jpql entitymanager