users@glassfish.java.net

Re: Persistence Context in JPA

From: Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>
Date: Fri, 04 May 2007 15:28:34 +0530

Hi Mayank,

glassfish_at_javadesktop.org wrote:
>> PC propagation rules won't be applicable when you use
>> different EMF in
>> caller and called components.
>>
>
> Hi Sahoo,
>
> Thanks for the reply.
>
> True, I already agree as "If a stateful session bean with an extended persistence context calls a stateful session bean with a different extended persistence context in the same transaction, an IllegalStateException would be thrown." Now can I infer from this that I can't access different configured data source(defined in different <persistence-unit> element in persistence.xml -> creation of different EMF -> different Persistence Context)?
>
Don't apply the above rule in isolation. Apply it in conjunction with
rule #4, which says "A PC is propagated when the called component uses
EM that belongs to the *same Entity Manager Factory* as the caller."
You can try a simple example to see it yourself. Also look at the
GlassFish error message shown below. It contains the phrase "same
EntityManagerFactory".
/javax.ejb.EJBException: There is an active transactional persistence
context for the same EntityManagerFactory as the current stateful
session bean's extended persistence context.

Sahoo
/
> With Regards,
> Mayank
>
> Have you tried doing
>
>> this? Are you seeing
>> any error?
>>
>
>
>
>> Thanks,
>> Sahoo
>> glassfish_at_javadesktop.org wrote:
>>
>>> Hi Sahoo,
>>>
>>>
>>>> Propagation of JTA transaction across session
>>>>
>> beans
>>
>>>> is independent of
>>>> use of JPA. Since you use different EMFs in those
>>>> session beans, you
>>>> would be using different persistence contexts in
>>>>
>> each
>>
>>>> of those bean's
>>>> context. Did it answer your question?
>>>>
>>>>
>>> That's my question, In the case I have different PC
>>>
>> among locally caller and called SFSB. But the
>> propagation requires the same PC, right? In other
>> words, If a stateful session bean with an extended
>> persistence context calls a stateful session bean
>> with a different extended persistence context in the
>> same transaction, an IllegalStateException would be
>> thrown.
>>
>>> Am I missing something here, as then I will not be
>>>
>> able to use a different PC of an EMF configured for
>> different data source.
>>
>>>
>>> Take a look at
>>>
>>>
>>>> [1] for an example
>>>> of PC propagation.
>>>>
>>>>
>>> I had a look at your explanation in the blog, I
>>>
>> must say it is very informative, my question is
>> related somewhat to rule#5. I guess, your example
>> uses the same datasource in the transaction of
>> ReportServlet where it calls the UCM Bean.
>>
>>> With Regards,
>>> Mayank
>>>
>>>
>>>
>>>
>>>
>>>> Thanks,
>>>> Sahoo
>>>> [1]
>>>>
>>>>
>> http://weblogs.java.net/blog/ss141213/archive/2006/10/
>>
>>>> persistence_con.html
>>>> glassfish_at_javadesktop.org wrote:
>>>>
>>>>
>>>>> As per JPA Spec section 5.6.3, "A single
>>>>>
>>>>>
>>>> persistence context may correspond to one or more
>>>>
>> JTA
>>
>>>> entity manager instance (all associated with the
>>>>
>> same
>>
>>>> entity manager factory).
>>>>
>>>>
>>>>> Now, If I require a JTA transaction to be
>>>>>
>>>>>
>>>> propagated among Stateful sesion beans and each
>>>> session bean is using different datasources (hence
>>>> having different persistence-units in same or
>>>> different 'persistence.xml' file and hence
>>>>
>> different
>>
>>>> EMFs)
>>>>
>>>>
>>>>> How am I going to acheive this using JPA?
>>>>>
>>>>> With Regards,
>>>>> Mayank
>>>>> [Message sent by forum member 'mayankmishra'
>>>>>
>>>>>
>>>> (mayankmishra)]
>>>>
>>>>
>>>>>
>>>>>
>> http://forums.java.net/jive/thread.jspa?messageID=2152
>>
>>>> 18
>>>>
>>>>
>>>>>
>>>>>
>> ------------------------------------------------------
>>
>>>> ---------------
>>>>
>>>>
>>>>> To unsubscribe, e-mail:
>>>>>
>>>>>
>>>> users-unsubscribe_at_glassfish.dev.java.net
>>>>
>>>>
>>>>> For additional commands, e-mail:
>>>>>
>>>>>
>>>> users-help_at_glassfish.dev.java.net
>>>>
>>>>
>>>>>
>>>>>
>>>>>
>> ------------------------------------------------------
>>
>>>> ---------------
>>>> To unsubscribe, e-mail:
>>>> users-unsubscribe_at_glassfish.dev.java.net
>>>> For additional commands, e-mail:
>>>> users-help_at_glassfish.dev.java.net
>>>>
>>>>
>>> [Message sent by forum member 'mayankmishra'
>>>
>> (mayankmishra)]
>>
>>>
>> http://forums.java.net/jive/thread.jspa?messageID=2154
>> 14
>>
>>>
>> ------------------------------------------------------
>> ---------------
>>
>>> To unsubscribe, e-mail:
>>>
>> users-unsubscribe_at_glassfish.dev.java.net
>>
>>> For additional commands, e-mail:
>>>
>> users-help_at_glassfish.dev.java.net
>>
>>>
>>>
>> ------------------------------------------------------
>> ---------------
>> To unsubscribe, e-mail:
>> users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail:
>> users-help_at_glassfish.dev.java.net
>>
> [Message sent by forum member 'mayankmishra' (mayankmishra)]
>
> http://forums.java.net/jive/thread.jspa?messageID=215467
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>