我正在使用 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
包含字符串“favorite-id”的实体。productsIds
有谁知道如何在标准 api中完成?
更新:
我认为以下 sql 应该可以解决问题,但我不知道如何在JPQL
or中做到这一点Criteria API
:
select * from favorites_folders join favorites_products on favorites_folders.id = favorites_products.folder_id where favorites_products.product_id = 'favorite-id'