[英]java jpa : list and sublist
我有一個堅持使用JPA的Java對象。 該對象具有成員“ friendsList”,該成員是字符串列表。 我已經在此對象上使用@CollectionOfElements休眠注釋。 這樣的結果是我有兩個表,一個表持久化我的對象,另一個表持久化每個對象的列表。
如何檢索(使用jpa)其列表包含“ hello”或“ world”的所有對象?
以下工作正常:它還將創建一個Parent_names
表以維護關系。 不要用@OneToMany注釋
@ElementCollection(targetClass = String.class)
private List<String> names;
或者我認為您可以嘗試一種解決方法:將字符串包裝在類中。
class FriendsName{
private String name;
//getter setter
}
然后,
class Parent{
@OneToMany
List<FriendsName> friendsName;
}
您可以像執行JPQL:
select p from Parent p where p.friendsName.name in ('hello','world')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.