我有一个实体(联系人),它有一个延迟加载的集合。我不知道要更改它,但是当我执行 em.find(Contact.class, myID) 时需要加载集合,这可以在不更改实体且不使用 jpql 语句和 fetch 的情况下完成。?
public class Contact implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name="contactId", nullable=false)
public String contactId;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "contact", orphanRemoval = true, fetch=FetchType.LAZY)
private List<ContactTaskRelation> taskRelations = new ArrayList<ContactTaskRelation>();
}
从我的无状态 bean
@PersistenceContext(unitName="myContext")
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Contact getContact(ContactMapping mappedContact){
//force em to load the collection of taskRelations
return em.find(Contact .class, mappedContact.getContact());
}