Monday, February 6, 2012

Hibernate prematurely flushing within RequestFactoryServlet while building object

I have a domain object that has references to several other domain objects, and also uses Hibernate and hibernate validation annotations.

I'm running into an issue where the order of the RF Servlet's loadDomainObject and setProperty calls is causing Hibernate to flush the entity before it is fully constructed, causing validation errors.

The scenario I am seeing is where you set a couple properties and also change a couple of relationships on an object and submit it.

On the server side I see:
  loadDomainObject calls for all of the original object and related objects.
  setProperty calls for some of the changed fields
  setProperty calls for one of the changed relationships
  loadDomainObject call for the changed relationship's new selected object.

That last loadDomainObject call is triggering Hibernate to flush the primary object, because it is doing a hibernate query and our environment doesn't support nested transactions.  

Does anyone know if there is a way to force the servlet to load all of the objects it needs, prior to dirtying any of them?   
Based on http://code.google.com/p/google-web-toolkit/wiki/RequestFactoryMovingParts#Flow it looks like that is what is supposed to happen, but I am seeing the newly selected objects being queried after some of the setProperty calls are already made.

Alternately, is there a way to get a list of the ".with(...)" properties at the time of the find() call?  If I had that, I could initialize the object and detach it from the session and avoid this problem.

Thanks,
Eric


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/vZIhT7hwOkIJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment