myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <simon.kitch...@chello.at>
Subject Re: [orchestra] unable to persist in sub thread
Date Thu, 01 Jan 1970 00:00:00 GMT
---- Dan Tran <dantran@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


Mime
View raw message