I would use the injected em for resolve the problem of lazy loading of entity child. for example to get the Orders collection from a Customer entity where the relatioship into Customer entity is BIDIRECTIONAL
@OneToMany (mappedby customer) Set <Order> orderslist I would use the Open Session In View pattern Like explained into http://stackoverflow.com/questions/1847040/open-session-in-view-pattern so into CustomerController when i select a Customer from table i merge it with em injected and i can get the Orderslist with the getOrdersList from selectedCustomer and iterate for get each order. With requestscoped em i can use the open session in view pattern like hibernate. Il 12/feb/2017 15:22, "Romain Manni-Bucau [via TomEE & OpenEJB]" < [email protected]> ha scritto: > Hi > > 2017-02-12 14:38 GMT+01:00 mauro2java2011 <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=4681055&i=0>>: > > > Hi all. > > > > I would use a requestscoped entitymanager into a viewaccesscoped > > controller. > > > > So i ask: > > > > The injected em requestscoped into controller viewscoped is a new em for > > each request or is all times the same into viewscoped controller? > > > > I know that the entity manager is not serializable. > > > > It is but it is not reliable in most cases > > > > So if the em is requestscoped i resolve the problem with tge > serialization > > of the em into viewaccesscoped cobtroller? > > > > I have to configure some thing for use jta into cdi injected em ? > > > > Jta scope = transaction so not sure it matches > > > > Into the class where i declare the method productor i have to use the > > > > @PersistenceContext (unitNane="namePU") > > private EntityManager em; > > > > @Produces > > @RequestScoped > > > > public EntityManager getEntityManager (){ > > return this.em; > > > > } > > > > Or i have to use the EntityManagerFactory with > > > > @PersistenceUnit (name="namePu") > > > > private EntityManagerFactory emf; > > > > public getEntityManager (){ > > return emf.createEntityManager; > > > > } > > > > public void closeEm (@Disposes EntityManager em){ > > > > em.close (); > > > > } > > > > > this works for resource_local EM > > > reading your mail it looks you just want a command pattern with a final > jta > transaction instead of immediate EM actions > > > > Tank you very much . > > > > Mauro > > > > > > > > > > -- > > View this message in context: http://tomee-openejb.979440. > > n4.nabble.com/EntityManager-into-controller-viewscoped-tp4681054.html > > Sent from the TomEE Users mailing list archive at Nabble.com. > > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > http://tomee-openejb.979440.n4.nabble.com/EntityManager- > into-controller-viewscoped-tp4681054p4681055.html > To unsubscribe from EntityManager into controller viewscoped, click here > <http://tomee-openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4681054&code=bWF1cm8yamF2YTIwMTFAZ21haWwuY29tfDQ2ODEwNTR8LTExMTcxODc2MjU=> > . > NAML > <http://tomee-openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://tomee-openejb.979440.n4.nabble.com/EntityManager-into-controller-viewscoped-tp4681054p4681056.html Sent from the TomEE Users mailing list archive at Nabble.com.
