You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Dan Tran <da...@gmail.com> on 2007/09/07 05:07:09 UTC

[orchestra] unable to persist in sub thread


I am running into this problem that I think it is related to the present of
Orchestra.

First I have a spring service bean which spins a thread, do the long work,
then save some data to persistent in the same thread.  The thread's runnable
contructor accept a reference to
the the same service bean to do the persistent. It works per my junit test.

Now I hook the same service bean to a couple of my master/detail jsf/spring
bean with the same
conversation name.  The trouble comes when the service bean try to save the
data, ever thing 
looks good but no data get saved ( it seems there are no injected
transaction)

I also have another unrelated service bean, not related to the conversation
, in the same thread and it can save its data.

Any suggestion to this problem is very very appreciated.

Thanks

-D




-- 
View this message in context: http://www.nabble.com/-orchestra--unable-to-persist-in-sub-thread-tf4395808.html#a12535168
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: [orchestra] unable to persist in sub thread

Posted by Dan Tran <da...@gmail.com>.

Btw, my app uses JSF, Acegi, Spring, JPA with Hibernate.  The spring
services bean has
@transactional annotation of its service methods. The service beans also use
a DAO layer
for persistent purpose.

-D



Dan Tran wrote:
> 
> 
> I am running into this problem that I think it is related to the present
> of Orchestra.
> 
> First I have a spring service bean which spins a thread, do the long work,
> then save some data to persistent in the same thread.  The thread's
> runnable contructor accept a reference to
> the the same service bean to do the persistent. It works per my junit
> test.
> 
> Now I hook the same service bean to a couple of my master/detail
> jsf/spring bean with the same
> conversation name.  The trouble comes when the service bean try to save
> the data, ever thing 
> looks good but no data get saved ( it seems there are no injected
> transaction)
> 
> I also have another unrelated service bean, not related to the
> conversation , in the same thread and it can save its data.
> 
> Any suggestion to this problem is very very appreciated.
> 
> Thanks
> 
> -D
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-orchestra--unable-to-persist-in-sub-thread-tf4395808.html#a12535554
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: [orchestra] unable to persist in sub thread

Posted by Dan Tran <da...@gmail.com>.

I found the solution for it using getter injection or @Configure annotation
for non spring bean.

-Dan



Dan Tran wrote:
> 
> 
> Create a new instance using a different name and manually inject it to my
> runnable solves the problem.
> 
> Now I have another concern, not related to Orchestra, where how to I
> create new instance on the fly
> (not thru spring configuration ) to be inject for each new thead ( yeah, I
> will have schedulers spin off
> threads left to right )
> 
> Comments are welcome, and thank you very much the advice on the previous
> issue.
> 
> Thanks
> 
> -D
> 
> Mario Ivankovits wrote:
>> 
>> Hi Dan!
>>> My thread has the same service bean that is in the main thread has, so I
>>> guess both thread sharing
>>> the same Persentent Context.
>>>
>>> Now I need to figure out how to Create my Persitent Context in the child
>>> thread which a little 
>>> disappointed.  My goal is to use the same service bean. Is there a way
>>> to
>>> use the same service bean
>>> but with diffrent persistent context?
>>>   
>> You mean the same instance of the bean or just the same class? The same
>> instance might not be possible.
>> But what if you configure your service bean two times? Then you'll be
>> able to get two instances.
>> 
>> If this wont help, could you provide some small code-pieces (spring
>> config, beans, service bean, thread stuff) to figuring out what you'll
>> going to do more exactly.
>> Maybe as a patch against our examples would be great.
>> 
>> 
>> Ciao,
>> Mario
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-orchestra--unable-to-persist-in-sub-thread-tf4395808.html#a12566528
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: [orchestra] unable to persist in sub thread

Posted by Dan Tran <da...@gmail.com>.

Create a new instance using a different name and manually inject it to my
runnable solves the problem.

Now I have another concern, not related to Orchestra, where how to I create
new instance on the fly
(not thru spring configuration ) to be inject for each new thead ( yeah, I
will have schedulers spin off
threads left to right )

Comments are welcome, and thank you very much the advice on the previous
issue.

Thanks

-D

Mario Ivankovits wrote:
> 
> Hi Dan!
>> My thread has the same service bean that is in the main thread has, so I
>> guess both thread sharing
>> the same Persentent Context.
>>
>> Now I need to figure out how to Create my Persitent Context in the child
>> thread which a little 
>> disappointed.  My goal is to use the same service bean. Is there a way to
>> use the same service bean
>> but with diffrent persistent context?
>>   
> You mean the same instance of the bean or just the same class? The same
> instance might not be possible.
> But what if you configure your service bean two times? Then you'll be
> able to get two instances.
> 
> If this wont help, could you provide some small code-pieces (spring
> config, beans, service bean, thread stuff) to figuring out what you'll
> going to do more exactly.
> Maybe as a patch against our examples would be great.
> 
> 
> Ciao,
> Mario
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-orchestra--unable-to-persist-in-sub-thread-tf4395808.html#a12566327
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: [orchestra] unable to persist in sub thread

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi Dan!
> My thread has the same service bean that is in the main thread has, so I
> guess both thread sharing
> the same Persentent Context.
>
> Now I need to figure out how to Create my Persitent Context in the child
> thread which a little 
> disappointed.  My goal is to use the same service bean. Is there a way to
> use the same service bean
> but with diffrent persistent context?
>   
You mean the same instance of the bean or just the same class? The same
instance might not be possible.
But what if you configure your service bean two times? Then you'll be
able to get two instances.

If this wont help, could you provide some small code-pieces (spring
config, beans, service bean, thread stuff) to figuring out what you'll
going to do more exactly.
Maybe as a patch against our examples would be great.


Ciao,
Mario


Re: [orchestra] unable to persist in sub thread

Posted by Dan Tran <da...@gmail.com>.
ahh!

My thread has the same service bean that is in the main thread has, so I
guess both thread sharing
the same Persentent Context.

Now I need to figure out how to Create my Persitent Context in the child
thread which a little 
disappointed.  My goal is to use the same service bean. Is there a way to
use the same service bean
but with diffrent persistent context?

Thanks for advice

-D

simon-118 wrote:
> 
> ---- Dan Tran <da...@gmail.com> schrieb:
>> 
>> 
>> I am running into this problem that I think it is related to the present
>> of
>> Orchestra.
>> 
>> First I have a spring service bean which spins a thread, do the long
>> work,
>> then save some data to persistent in the same thread.  The thread's
>> runnable
>> contructor accept a reference to
>> the the same service bean to do the persistent. It works per my junit
>> test.
>> 
>> Now I hook the same service bean to a couple of my master/detail
>> jsf/spring
>> bean with the same
>> conversation name.  The trouble comes when the service bean try to save
>> the
>> data, ever thing 
>> looks good but no data get saved ( it seems there are no injected
>> transaction)
>> 
>> I also have another unrelated service bean, not related to the
>> conversation
>> , in the same thread and it can save its data.
>> 
>> Any suggestion to this problem is very very appreciated.
> 
> Well, if you're doing stuff in a thread started during a request then you
> had better be using a different persistence context than the one the main
> request is using. Persistence contexts (JPA EntityManager, Hibernate
> Session, etc) are explicitly not thread-safe.
> 
> And of course stuff in the main request thread is going to be messing with
> the transaction associated with its persistence context - committing,
> rolling back, closing the connection, etc.
> 
> If you are using a new persistence context for your thread, then I'm not
> sure what the problem would be, as that new context should have its own
> private Connection which therefore has its own transaction.
> 
> Regards,
> 
> Simon
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-orchestra--unable-to-persist-in-sub-thread-tf4395808.html#a12536974
Sent from the My Faces - Dev mailing list archive at Nabble.com.