这里是我的代码:如何返回JPA中最大集合的大小?
@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向导,但你的解决方案已经奏效!谢谢! – Vladislav 2014-08-30 10:40:05