After much stepping through GWT and Hibernate source code, I believe I
have come upon an incompatibility in the way that RequestFactory and
Hibernate/JPA interact.

I have a domain object named Survey, and a proxy named SurveyProxy.
Survey contains a Set of SurveyPermission objects, as follows:

public class Survey {
  private Set<SurveyPermission> surveyPermissions;

  @OneToMany(mappedBy="survey", orphanRemoval=true)
  @Cascade(value={CascadeType.ALL})
  public Set<SurveyPermission> getSurveyPermissions () {
    return surveyPermissions;
  }
}

SurveyProxy contains a method to retrieve the set of SurveyPermissions
owned by the Survey:
public Set<SurveyPermissionProxy> getSurveyPermissions ();

In my client code, I load a Survey object, and then send it back to
the server (unmodified), and then perform a save on the object:

Session session = HibernateUtil.getCurrentSession();
session.save(survey);
session.flush();

When I do this, I get an exception from Hibernate:
A collection with cascade="all-delete-orphan" was no longer referenced
by the owning entity instance:
edu.hope.cs.surveys.dao.pojo.Survey.surveyPermissions

Research on the web shows that the cause of this is when the setter
for a collection is called, when Hibernate is expecting to manage the
collection itself.

Going through the RequestFactoryServlet code, I see that
SimpleRequestProcessor's processOperationMessages (final RequestState
state, RequestMessage re) method  (called by RequestFactoryServlet in
doPost) calls
bean.accept ()
which basically uses the visitor pattern to call setters for each
property referenced by the proxy.

But this is problematic for Hibernate, because now some outside code
has called the setter for one the collections it is managing, and at
least when orphanRemoval is set to true, Hibernate does not like this.

I'm afraid the answer to this question is "Yes, this is a problem, you
can't use collections with orphanRemoval set to true."  If anyone
familiar enough with the RequestFactory implementation and Hibernate
semantics can verify that this is a problem, then I can file a bug
report and try to work around it in my code.

Thanks!
Ryan

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to