【发布时间】:2012-05-22 19:30:43
【问题描述】:
我正在使用 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",
joinColumns=@JoinColumn(name="folder_id")
)
@Column(name="product_id")
@NotNull
private Set<String> productsIds = new HashSet<String>();
}
我想要做的是获得一组FavoritesFolder 实体,它们在其productsIds 成员集中包含字符串“favorite-id”。
有谁知道如何在 criteria 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'
【问题讨论】:
标签: jpa collections criteria-api