我有两个实体,实体申请人,实体 JobApplications。关系是
//Entity Applicants
public class AppPers implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "appPers",fetch = FetchType.EAGER)
private Collection<JobApplications> jobApplicationsCollection;
.........................
}
//Entity JobApplications
public class JobApplications implements Serializable {
@JoinColumn(name = "app_id", referencedColumnName = "APP_ID", insertable = false, updatable = false)
@ManyToOne(optional = false,fetch = FetchType.EAGER)
private AppPers appPers;
所以在我合并之后
AppPers ap =em.find(AppPers.class,appId);
ap.setJobApplicationsCollection(c);
em.merge(ap);
em.refresh(ap);
并尝试执行
//fetch the newly created list
List<JobApplications> list = new ArrayList<JobApplications>();
list = em.createNamedQuery("JobApplications.findAll").getResultList();
//list size is 3 in my case
for( JobApplications ja: list) {
String a = ja.getAppPers().getSurName();
}
surName 是 AppPers 的一列,我得到 NullPointer 异常。这会发生,直到我重新启动 Glassfish,然后空指针不会发生。我尝试将 fetch 设置为 Eager,但仍然没有乐趣。我可能会错过什么