You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by alsha <al...@menta.de> on 2008/06/02 11:43:59 UTC

[Orchestra] is it possible to load entities from different persistence contextes in the same conversation?

Hi,

I am using Hibernate and have 2 session factories congigured:

1. sessionFactory -> persistentContextFactory
2. dmsSessionFactory -> dmsPersistentContextFactory

Each one has its own interceptor (persistentContextConversationInterceptor
and dmsPersistentContextConversationInterceptor).

Now I configure my conversation scope as follows:

...
          <entry key="conversation.manual">
            <bean
class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
              <!--<property name="timeout" value="15" /-->
              <property name="advices">
                <list>
               	  <ref bean="persistentContextConversationInterceptor" />
               	  <ref bean="dmsPersistentContextConversationInterceptor" />
                </list>
              </property>
            </bean>
          </entry>
...

But it seems, like only the first interceptor works (For example, the
entities from dmsSessionFactory couldn't be loaded lazyly...)

What I am doing wrong?

Thanks in advance for any help!

-- 
View this message in context: http://www.nabble.com/-Orchestra--is-it-possible-to-load-entities-from-different-persistence-contextes-in-the-same-conversation--tp17597557p17597557.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: [Orchestra] is it possible to load entities from different persistence contextes in the same conversation?

Posted by "simon.kitching@chello.at" <si...@chello.at>.
I think you could define a scope called 'conversation.manual.dms' or
similar, and configure that to use your persistence context factory that
is set up for 'dms' access. Then you can declare bean A as belonging to
scope 'conversation.manual', and B as belonging to scope
'conversation.manual.dms'.

Of course I haven't tried it; I've never had a need to deal with
multiple persistence contexts. But I don't see why it wouldn't work.

You can inject a bean B from one conversation into a bean A in a
different conversation using normal Spring functionality. When A calls a
method on B, then the "current conversation" gets switched to B's
conversation automatically, including setting the right persistence
context. Anything bean B does will be within its own persistence context.

Regards,
Simon


alsha schrieb:
> Hi Simon,
>
> thank you for fast reply!
>
> I see the problem. 
> Anyway, what is the solution for my case? I can define 2 beans, each in it
> own scope.
> But how can I get the "intercepted" reference of one bean in another bean? 
>
> Regards,
> Alexey
>
>
> simon.kitching@chello.at wrote:
>   
>> alsha schrieb:
>>     
>>> Hi,
>>>
>>> I am using Hibernate and have 2 session factories congigured:
>>>
>>> 1. sessionFactory -> persistentContextFactory
>>> 2. dmsSessionFactory -> dmsPersistentContextFactory
>>>
>>> Each one has its own interceptor
>>> (persistentContextConversationInterceptor
>>> and dmsPersistentContextConversationInterceptor).
>>>
>>> Now I configure my conversation scope as follows:
>>>
>>> ...
>>>           <entry key="conversation.manual">
>>>             <bean
>>> class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
>>>               <!--<property name="timeout" value="15" /-->
>>>               <property name="advices">
>>>                 <list>
>>>                	  <ref bean="persistentContextConversationInterceptor" />
>>>                	  <ref bean="dmsPersistentContextConversationInterceptor"
>>> />
>>>                 </list>
>>>               </property>
>>>             </bean>
>>>           </entry>
>>> ...
>>>
>>> But it seems, like only the first interceptor works (For example, the
>>> entities from dmsSessionFactory couldn't be loaded lazyly...)
>>>
>>> What I am doing wrong?
>>>   
>>>       
>> You're doing nothing wrong, it just isn't currently supported by
>> Orchestra.
>>
>> Class PersistenceContextConversationInterceptor stores the current
>> conversation context into a conversation attribute using key
>> PERSISTENCE_CONTEXT_CONV_ATTRIBUTE. So only one persistence context per
>> conversation is supported.
>>
>> By the way, if Orchestra did support multiple persistence contexts, then
>> how would code specify which was being used with which operation (in
>> particular, with the @Transactional annotation)?
>>
>> Regards,
>> Simon
>>
>>
>>
>>     
>
>   


Re: [Orchestra] is it possible to load entities from different persistence contextes in the same conversation?

Posted by alsha <al...@menta.de>.
Hi Simon,

thank you for fast reply!

I see the problem. 
Anyway, what is the solution for my case? I can define 2 beans, each in it
own scope.
But how can I get the "intercepted" reference of one bean in another bean? 

Regards,
Alexey


simon.kitching@chello.at wrote:
> 
> alsha schrieb:
>> Hi,
>>
>> I am using Hibernate and have 2 session factories congigured:
>>
>> 1. sessionFactory -> persistentContextFactory
>> 2. dmsSessionFactory -> dmsPersistentContextFactory
>>
>> Each one has its own interceptor
>> (persistentContextConversationInterceptor
>> and dmsPersistentContextConversationInterceptor).
>>
>> Now I configure my conversation scope as follows:
>>
>> ...
>>           <entry key="conversation.manual">
>>             <bean
>> class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
>>               <!--<property name="timeout" value="15" /-->
>>               <property name="advices">
>>                 <list>
>>                	  <ref bean="persistentContextConversationInterceptor" />
>>                	  <ref bean="dmsPersistentContextConversationInterceptor"
>> />
>>                 </list>
>>               </property>
>>             </bean>
>>           </entry>
>> ...
>>
>> But it seems, like only the first interceptor works (For example, the
>> entities from dmsSessionFactory couldn't be loaded lazyly...)
>>
>> What I am doing wrong?
>>   
> 
> You're doing nothing wrong, it just isn't currently supported by
> Orchestra.
> 
> Class PersistenceContextConversationInterceptor stores the current
> conversation context into a conversation attribute using key
> PERSISTENCE_CONTEXT_CONV_ATTRIBUTE. So only one persistence context per
> conversation is supported.
> 
> By the way, if Orchestra did support multiple persistence contexts, then
> how would code specify which was being used with which operation (in
> particular, with the @Transactional annotation)?
> 
> Regards,
> Simon
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-Orchestra--is-it-possible-to-load-entities-from-different-persistence-contextes-in-the-same-conversation--tp17597557p17600111.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: [Orchestra] is it possible to load entities from different persistence contextes in the same conversation?

Posted by "simon.kitching@chello.at" <si...@chello.at>.
alsha schrieb:
> Hi,
>
> I am using Hibernate and have 2 session factories congigured:
>
> 1. sessionFactory -> persistentContextFactory
> 2. dmsSessionFactory -> dmsPersistentContextFactory
>
> Each one has its own interceptor (persistentContextConversationInterceptor
> and dmsPersistentContextConversationInterceptor).
>
> Now I configure my conversation scope as follows:
>
> ...
>           <entry key="conversation.manual">
>             <bean
> class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
>               <!--<property name="timeout" value="15" /-->
>               <property name="advices">
>                 <list>
>                	  <ref bean="persistentContextConversationInterceptor" />
>                	  <ref bean="dmsPersistentContextConversationInterceptor" />
>                 </list>
>               </property>
>             </bean>
>           </entry>
> ...
>
> But it seems, like only the first interceptor works (For example, the
> entities from dmsSessionFactory couldn't be loaded lazyly...)
>
> What I am doing wrong?
>   

You're doing nothing wrong, it just isn't currently supported by Orchestra.

Class PersistenceContextConversationInterceptor stores the current
conversation context into a conversation attribute using key
PERSISTENCE_CONTEXT_CONV_ATTRIBUTE. So only one persistence context per
conversation is supported.

By the way, if Orchestra did support multiple persistence contexts, then
how would code specify which was being used with which operation (in
particular, with the @Transactional annotation)?

Regards,
Simon