tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Problem with entityManager and Open EJB 3.1
Date Fri, 06 Feb 2009 22:51:21 GMT
Hi Guys,

Not entirely sure on the Seam angle, but in terms of  
javax.ejb.PersistenceContextType.EXTENDED the persistence context  
automatically propagates from the SFSB that created it to any SFSBs  
that that bean created either via injection or JNDI lookup.

Here's a test case which illustrates:

http://svn.apache.org/repos/asf/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java

Note the test methods have underscores only so we can run them all  
together via the main test method.

And a quote from the JPA 1.0 spec:

    5.6.2.1 Inheritance of Extended Persistence Context

    If a stateful session bean instantiates a stateful session
    bean which also has such an extended persistence context, the
    extended persistence context of the first stateful session
    bean is inherited by the second stateful session bean and
    bound to it, and this rule recursively applies --
    independently of whether transactions are active or not at
    the point of the creation of the stateful session beans.

    If the persistence context has been inherited by any stateful
    session beans, the container does not close the persistence
    context until all such stateful session beans have been
    removed or otherwise destroyed.

Seam may leveraging it in some way, but the underlying EXTENDED  
persistence context is provided by the EE container.

So long story short, this may not be a Seam issue as all they can do  
is provide some syntactic sugar over the EE container's actual  
EXTENDED persistence context.

I guess my first question would be is this in use in a test case or in  
another environment like Tomcat?  If in a test case, how do the setup  
and tear down's work?  I.e. are OpenEJB and Seam being torn down  
together and are they being torn down before and after each test, or  
once before all tests and once after?


-David


On Feb 5, 2009, at 6:20 AM, Olivier THIERRY wrote:

> Hi Thomas,
>
> All my SFSB are also Seam components and live in conversation context.
> So the extended persistence context is kept in a Seam conversation.
> For what I understood, if you don't use Seam you have to propagate the
> persistence context yourself.
>
> You can read this in Seam documentation :
>
> "Seam grew out of the frustration of the Hibernate team with the
> statelessness typical of the
> previous generation of Java application architectures. The state
> management architecture of
> Seam was originally designed to solve problems relating to
> persistence—in particular problems
> associated with optimistic transaction processing. Scalable online
> applications always use
> optimistic transactions. An atomic (database/JTA) level transaction
> should not span a user
> interaction unless the application is designed to support only a very
> small number of concurrent
> clients. But almost all interesting work involves first displaying
> data to a user, and then, slightly
> later, updating the same data. So Hibernate was designed to support
> the idea of a persistence
> context which spanned an optimistic transaction.
> Unfortunately, the so-called "stateless" architectures that preceded
> Seam and EJB 3.0 had no
> construct for representing an optimistic transaction. So, instead,
> these architectures provided
> persistence contexts scoped to the atomic transaction. Of course, this
> resulted in many problems
> for users, and is the cause of the number one user complaint about
> Hibernate: the dreaded
> LazyInitializationException. What we need is a construct for
> representing an optimistic
> transaction in the application tier.
> EJB 3.0 recognizes this problem, and introduces the idea of a stateful
> component (a stateful
> session bean) with an extended persistence context scoped to the
> lifetime of the component. This
> is a partial solution to the problem (and is a useful construct in and
> of itself) however there are
> two problems:
> • The lifecycle of the stateful session bean must be managed manually
> via code in the web tier
> (it turns out that this is a subtle problem and much more difficult in
> practice than it sounds).
> • Propagation of the persistence context between stateful components
> in the same optimistic
> transaction is possible, but tricky.
> Seam solves the first problem by providing conversations, and stateful
> session bean components
> scoped to the conversation. (Most conversations actually represent
> optimistic transactions in the
> data layer.) This is sufficient for many simple applications (such as
> the Seam booking demo)
> where persistence context propagation is not needed. For more complex
> applications, with many
> loosly-interacting components in each conversation, propagation of the
> persistence context across
> components becomes an important issue. So Seam extends the persistence
> context management
> model of EJB 3.0, to provide conversation-scoped extended  
> persistence contexts."
>
> So I could make it work using Seam. But I have no idea how you should
> do this without Seam !
>
> Hope it helps.
>
> Olivier
>
>
> 2009/2/5  <Thomas.TH.Hamacher@partner.bmw.ch>:
>> Hi Olivier,
>>
>> I´m currently struggling with using the Extended PersistenceContext  
>> in multiple SFSB.
>> Can you tell me, if it is working for you and what you did to make  
>> it work.
>> As soon as I try to inject the same EntityManager into another  
>> SessionBean I get the following error:
>>
>> DEBUG - finished invoking method create with  
>> exception:javax.ejb.EJBException: nested exception is:  
>> org 
>> .apache 
>> .openejb.persistence.EntityManagerAlreadyRegisteredException:  
>> Another entity manager is already registered for this persistence  
>> unit
>> javax.ejb.EJBException: nested exception is:  
>> org 
>> .apache 
>> .openejb.persistence.EntityManagerAlreadyRegisteredException:  
>> Another entity manager is already registered for this persistence  
>> unit
>> org 
>> .apache 
>> .openejb.persistence.EntityManagerAlreadyRegisteredException:  
>> Another entity manager is already registered for this persistence  
>> unit
>> at org.apache.openejb.persistence.JtaEntityManagerRegistry 
>> $ExtendedRegistry.addEntityManagers(JtaEntityManagerRegistry.java: 
>> 191)
>> at org.apache.openejb.persistence.JtaEntityManagerRegistry 
>> $ExtendedRegistry.access$100(JtaEntityManagerRegistry.java:169)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .persistence 
>> .JtaEntityManagerRegistry 
>> .addEntityManagers(JtaEntityManagerRegistry.java:129)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .core 
>> .stateful.StatefulContainer.createEJBObject(StatefulContainer.java: 
>> 288)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .core.stateful.StatefulContainer.invoke(StatefulContainer.java:263)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .core.ivm.EjbHomeProxyHandler.create(EjbHomeProxyHandler.java:270)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .core.ivm.EjbHomeProxyHandler._invoke(EjbHomeProxyHandler.java:161)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:286)
>> at $Proxy75.create(Unknown Source)
>> at  
>> org 
>> .apache 
>> .openejb 
>> .core 
>> .ivm 
>> .naming 
>> .BusinessLocalReference.getObject(BusinessLocalReference.java:33)
>> at  
>> org 
>> .apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java: 
>> 150)
>> at  
>> org 
>> .apache 
>> .openejb.core.ivm.naming.ContextWrapper.lookup(ContextWrapper.java: 
>> 115)
>> at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>
>> Any help would be greatly appriciated
>>
>> Thanks
>> Thomas
>>
>>
>>> Hi,
>>>
>>
>


Mime
View raw message