both, findEmployee() and persist() created a new EntityManager() and closed it after the work is done.
So each request creates a new EntityManager instance and close it.
Request<Void> updateReq = request.persist().using(editableEmployee );
This request once fired to the server will first do a findEmployee internally so RequestFactory has an Employee instance on which it can apply your modifications. Then RequestFactory takes the modified instances and calls persist() on it. As you have two EntityManager instances for this single server request the persist() method is called on a detached entity as you have closed the first EntityManager and want to persist the changes using a new empty EntityManager. Thats why you have to use merge() right now.
You should avoid creating two or more EntityManager instances for a single server request. Your EntityManager should behave like a singleton during a single server request. This also ensures that RF sees the same entity instance if RF needs to fetch the entity multiple times.
By using a servlet filter your flow is more like:
EntityManager em = create(); //save this em instance somewhere so you can access it in your RF service methods, e.g. using a static ThreadLocal
filterChain.doFilter() //this calls the RF servlet and does all the RF requests
em.close() //Don't forget to cleanup the ThreadLocal if you have used one.
-- J.
-- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment