我正在使用 JPA 进行持久性的 GXT 项目,但我面临双向关系持久性的问题。
我有这两个实体:
@Entity
@Table(name = "ACTV_REQ", catalog = "erpdb")
@AttributeOverride(name = "id", column = @Column(name = "ID", nullable = false, columnDefinition = "BIGINT UNSIGNED"))
@NamedQueries(value = {
@NamedQuery(name = "findByPerson", query="select object(m) from ActvReq m where m.people= :people")
})
public class ActvReq extends BaseEntity {
@ManyToOne
@JoinColumn(name = "PPL_ID")
@NotNull
private People people;
@ManyToOne
@JoinColumn(name = "ACTV_TYP_ID")
private ActivityTyp actvTyp;
@ManyToOne
@JoinColumn(name= "PPL_ACTV_RIGHT_ID")
private PeopleActvRight pplActvRight;
@Column(name = "DESCR")
private String desc;
}
和 :
@Entity
@Table(name = "PPL_ACTV_RIGHT", catalog = "erpdb")
@AttributeOverride(name = "id", column = @Column(name = "ID", nullable = false, columnDefinition = "BIGINT UNSIGNED"))
@PeopleActvRightBeanConstraint
@NamedQueries(value = {
@NamedQuery(name = "findByPeople", query="select object(m) from PeopleActvRight m where m.people= :people")
})
public class PeopleActvRight extends BaseEntity {
@ManyToOne
@JoinColumn(name="ACTV_TYP_ID")
@NotNull
ActivityTyp type;
@ManyToOne
@JoinColumn(name="PPL_ID")
@NotNull
People people;
@ManyToOne
@JoinColumn(name="ACTV_RIGHT_ID")
ActvRight actvRight;
@OneToMany(mappedBy="pplActvRight",cascade=CascadeType.ALL)
private List<ActvReq> actvRequests = new ArrayList<ActvReq>();
}
(我没有复制 getter 和 setter,但这些方法存在。)
对于 ActvReqProxy 的持久性,在我的 EditorPresenter 中基本上是这样完成的:
getRequestContext().persistAndReturn(getModel()).with("actvTyp","people","pplActvRight").fire(new Receiver<M>() {
@Override
public void onSuccess(M response) {
unsetContext();
onSaveSuccess( response );
}
});
在我得到的响应中,响应 pplActvRight 已经为空,但是在 getModel() 中设置了 pplActvReqProxy。
在服务器端,我有一个服务,它调用我的 DAO 的以下方法:
public ActvReq persistAndReturn(ActvReq entity){
em.getTransaction().begin();
em.persist(entity);
em.close;
return entity;
}
当我尝试从我的编辑器中持久化 ActvReqProxy 时,使用 with("pplActvRight","people",actvType") 方法,我没有收到任何错误,但在我的数据库中,实体并没有完全持久化。我意味着在数据库中创建了一个新的 ActvReq 但字段 PPL_ACTV_RIGHT_ID 保持为空。(它适用于人和 actvTyp)
编辑:事实上我假设问题位于resolveDomainValue中的GWT Resolver上,它无法解析属性pplActvRight。就好像我的 EntityProxy 对象在服务器端不存在。
有任何想法吗?