Monday, February 4, 2013

Re: RequestFactory - EntityManager and Server Side Question



On Monday, February 4, 2013 11:16:50 AM UTC+1, Manuel wrote:
Hi Jens,

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.

You SHOULD (as in "must unless you really really know what you're doing") use a session-per-request (aka OpenSessionInView) pattern with RequestFactory.
 
But when i want to persist() my Entity (that i received from server, and is already stored in the db), it says its detached. Thats why I wonder how to persist() / update a object.
As i mentioned, using EntityManager.merge() instead of EntityManager.persist() works fine, but im not sure, if this bring problems with a more difficult data structure.

This is just how JPA works: when you close() an EntityManager, all its managed entities are detached (as if by a call to EntityManager#detach()); you then have to attach them to another EntityManager, this is what merge() does.
 
Or just using  one EntityManager for all clients, allows to use persist(), cause the entity wont be detached.

"Typically you could create a single EntityManager instance in a servlet filter"

Im not familir to the filter. But i guess its already working that way.


Google for "OpenSessionInView filter" or "session per request".

--
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