JPA:如何热切地获取嵌入式元素集合
请考虑以下模型
@Entity
// JPA and JAXB annotations here
public class Employee implements Serializable {
// other fields, annotations, stuffs
...
@ElementCollection(fetch = FetchType.LAZY,
targetClass = Address.class)
@CollectionTable(name = "employee_address",
schema = "hris",
joinColumns = @JoinColumn(name = "employee_id",
nullable = false,
referencedColumnName = "employee_id",
foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT)))
protected Set<Address> addresses;
// setters, getters
...
}
@Embeddable
// JAXB annotations here
public class Address implements Serializable {
// fields, setters, getters
}
该类使用批注进行批注,并且该类具有 嵌入的元素集合 。元素集合的 设置为 。现在,我想创建一个可以检索地址已热切初始化的所有员工。知道这仅适用于使用 JPA 2.1 注释或基于 JPA 2.1 的实体集合,我将如何创建一个有效的查询,使我能够热切地检索嵌入元素集合?Address
@Embeddable
Employee
addresses
fetch
FetchType.LAZY
@NamedQuery
JOIN FETCH
@OneToMany
@ManyToMany
JPQL