hmm, aren't you used to produce your own em instead of using a container
one? whatever you can use a stateful directly to achieve it but you can't
produce an extended em.

The spec is not that clear about it, it says the extended em is bound to
the stateful. You can still wrap your calls in the stateful
(call(Callable)) but it is a bit less elegant.

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/6/26 Mark Struberg <[email protected]>

> Why should it not be allowed?
> There are even samples for a PersistenceContext producer field in the CDI
> spec. They are not EXTENDED though.
>
> > Btw not sure what you want to achieve with it...
> That one is pretty easy to explain. By default when working without DTOs
> but with plain entities on the frontend you need to em.merge() the entity
> on any postback because otherwise lazy loading and navigation would not
> work. But this has the side effect that changes in the entity automatically
> get stored in the database - even if the user didn't want to because he
> didn't yet press the 'Save' button.
>
> By using an unsynchronized transaction context and explicitly call
> em.joinTransactio() when in the save() action, all the changes in the DB
> only happens when the user really likes to store it.
>
> All the trick with the EntityManager producer is just to make sure there
> is no synchronized transaction attached to the EM on the postback.
>
> got me?
>
> LieGrue,
> strub
>
>
>
>
> ----- Original Message -----
> > From: Romain Manni-Bucau <[email protected]>
> > To: Mark Struberg <[email protected]>; [email protected]
> > Cc:
> > Sent: Tuesday, 25 June 2013, 17:37
> > Subject: Re: em.find outside of a JTA transaction
> >
> > Hi Mark
> >
> > You produce an extended em, that's not allowed i think (i didnt say it is
> > forbidden). Btw not sure what you want to achieve with it...
> > Le 25 juin 2013 17:13, "Mark Struberg" <[email protected]> a
> > écrit :
> >
> >>
> >>
> >>  Hi!
> >>
> >>  According to the spec all read operations on an EntityManager should
> work
> >>  and only write operations must be queued up until em.joinTransaction()
> gets
> >>  called.
> >>  Is this correct?
> >>
> >>  Maybe I have an error in my sample, but I get a nasty Exception in my
> >>  sample.
> >>
> >>  https://github.com/struberg/jta_test
> >>  just mvn clean install
> >>
> >>  java.lang.IllegalStateException: InternalError: an entity manager
> should
> >>  already be registered for this extended persistence unit
> >>      at
> >>
> >
> org.apache.openejb.persistence.JtaEntityManagerRegistry.getEntityManager(JtaEntityManagerRegistry.java:99)
> >>      at
> >>
> >
> org.apache.openejb.persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java:91)
> >>      at
> >>
> >
> org.apache.openejb.persistence.JtaEntityManager.find(JtaEntityManager.java:164)
> >>      at
> >>
> >
> org.apache.webbeans.custom.persistence.EntityManager$$OwbNormalScopeProxy0.find(javax/persistence/EntityManager.java)
> >>      at
> >>  at.struct.jpatest.CustomerService.loadCustomer(CustomerService.java:56)
> >>      at
> >>
> >
> at.struct.jpatest.CustomerService$$OwbNormalScopeProxy0.loadCustomer(at/struct/jpatest/CustomerService.java)
> >>      at at.struct.jpatest.StoreTest.assertSurName(StoreTest.java:67)
> >>      at
> at.struct.jpatest.StoreTest.testCustomerLifecycle(StoreTest.java:41)
> >>
> >>  LieGrue,
> >>  strub
> >>
> >
>

Reply via email to