I'm working on a GXT project using JPA for persistence, but I'm facing an issue with bidirectionnal relationship persistence.
I have those two Entities :
@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;
}
And :
@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>();
}
(I did not copy getters and setters but thoses methods exists.)
For the persistence of ActvReqProxy, it's basically done that way in my EditorPresenter :
getRequestContext().persistAndReturn(getModel()).with("actvTyp","people","pplActvRight").fire(new Receiver<M>() {
@Override
public void onSuccess(M response) {
unsetContext();
onSaveSuccess( response );
}
});
And the response pplActvRight is already null in the response I get, but in getModel() pplActvReqProxy is set.
On server side I've a service which calls the following method of my DAO :
public ActvReq persistAndReturn(ActvReq entity){
em.getTransaction().begin();
em.persist(entity);
em.close;
return entity;
}
And when I'm trying to persist a ActvReqProxy from my editor, using method with("pplActvRight","people",actvType"), I don't get any errors, but in my DB the entity is not entirely persisted. I mean a new ActvReq is created in the DB but field PPL_ACTV_RIGHT_ID remains null. (It works fine for people and actvTyp)
EDIT : In fact I assume the problem is located on GWT Resolver in resolveDomainValue, it can not resolve the attribute pplActvRight. It's as if my EntityProxy object doesn't exists on server-side.
Any ideas?
So at the beginning of persistAndReturn
on server side it is already null
? If so, then at least we know that it has nothing to do with JPA.
And you're sure that on client side it is set to something other than null
on proxy before calling persistAndReturn
? You can easily verify it: using Eclipse debugger it is possible to see JSON code to which proxy will be serialized (one of fields of proxy that you can see when you select proxy object in debugger). Please make sure that pplActvRight
key is there with not-null value.
If so, maybe you should debug GWT source code that translates proxies to server-side entities to check what is being done with that pplActvRight
property (why isn't it assigned to corresponding ActvReq
server side instance). I can't remember what the class name doing this stuff was but if you won't be able to find it I can search it for you.