我使用JPA其收藏價值要查詢的實體和我有以下實體:如何通過
@Entity
@Table(name="favorites_folders")
public class FavoritesFolder {
private static final long serialVersionUID = 1L;
@Id
private String id;
@NotNull
@Size(min = 1, max = 50)
public String name;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(
name="favorites_products",
[email protected](name="folder_id")
)
@Column(name="product_id")
@NotNull
private Set<String> productsIds = new HashSet<String>();
}
我想要做的是讓一組包含字符串FavoritesFolder
實體的「最愛-id「在他們的productsIds
成員集中。
有沒有人知道如何在準則API?
更新:
我想下面的SQL應該做的伎倆,但我不知道如何做到這一點在任何JPQL
或Criteria API
:
select * from favorites_folders join favorites_products on favorites_folders.id = favorites_products.folder_id where favorites_products.product_id = 'favorite-id'
我知道這個話題,我們reffering爲ID的,因此他們必須等於匹配,但假設我們有一個'Collection',我們可以做基本相同的事情,但是不需要一個項目是'相等的',我們可以使用'LIKE'來匹配項目MATCH? –
dominicbri7
@ dominicbri7在相關[問題](http://stackoverflow.com/questions/7066122/how-to-make-a-like-query-to-elementcollection-of-type-map?rq=1)我發現解決方案。使用root類'cb.like(from.join(「apples」)。get(「color」),textParameter)上的join方法' – cirovladimir