2
我有以下兩個實體:JPA命名查詢來獲得尺寸的集合
@Entity
class Relation{
@ManyToOne
private User user;
//some other fields
...
}
用戶實體有其他實體的集合:
@Entity
class User {
@OneToMany(mappedBy="user")
private Collection<Address> addresses = new ArrayList<Address>();
}
//some other fields
}
是否有可能寫入一個名爲在Relation實體中查詢,它給了我有超過2個地址的用戶......? 喜歡:
@NamedQuery("SELECT m from Membership m where m.otherfield = ?1 AND m.user.addresses > 2")
,我怎麼能得到這個實體的大小與命名查詢?
thx
爲什麼不使用'SELECT COUNT(m)from ....'? – Osw 2012-03-29 17:47:15