tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier THIERRY <olivier.thie...@gmail.com>
Subject Re: Problem with entityManager and Open EJB 3.1
Date Thu, 05 Feb 2009 14:20:57 GMT
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