给定
@Entity
public class Document {
@Id
@Column(name = "DOCUMENT_ID")
private Long id;
@ElementCollection
@CollectionTable(
name="TAG",
joinColumns=@JoinColumn(name="DOCUMENT_ID")
)
@Column(name="TAG")
private Set<String> tags;
}
查找使用特定标签集合标记的所有文档。本质上,EclipseLink 相当于:
SELECT d FROM Document d WHERE :tag1 MEMBER OF d.tags
INTERSECT
SELECT d FROM Document d WHERE :tag2 MEMBER OF d.tags
...
SELECT d FROM Document d WHERE :tagn MEMBER OF d.tags
但使用 JPA CritieraQuery。