You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Wadi Jalil Maluf <wa...@yahoo.com.ar> on 2010/02/15 20:02:45 UTC

@Transactional in another thead?

Hi all,
          Im using Spring @Transactional anotation to handle 
trasnactions. The thing is that I have a Service that opens another 
thread and later calls a method using @Transactional . Whe I do that I 
get a TransactionRequired exception, does anyone know how ca I deal with 
@Transactional and multiple threads?Why is this a problem, am I missing 
something?Any help would be appreciatted,
Thanks in advance,
Ernest


__________ Información de ESET Smart Security, versión de la base de firmas de virus 4869 (20100215) __________

ESET Smart Security ha comprobado este mensaje.

http://www.eset.com




Re: @Transactional in another thead?

Posted by Andreas Veithen <an...@gmail.com>.
Andrew,

Of course the concept already exists in JTA, otherwise Spring would
not be able to do transaction suspension. The added value that Spring
provides in this area is that (1) it offers a single API that is
independent of the actual transaction API used (local transaction,
JTA, Hibernate, etc.) and (2) shields the developer from application
server specific details. With respect to the second point: since you
know the specs so well, you ought to know that TransactionManager is
an API that is exposed to transactional resources, but that the J2EE
specs don't require an app server to expose that API to an application
(unless that has changed in recent versions of the specs). Most
servers do this, but each server does it in a different way. As you
can see, Spring is not just wrapping the existing API "to make it look
like they have done some work"...

That being said, of course using the JTA APIs directly might be an
option for Wadi.

Regards,

Andreas

On Wed, Feb 17, 2010 at 10:44, Andrew Dinn <an...@googlemail.com> wrote:
> On 02/16/2010 06:25 PM, Andreas Veithen wrote:
>>
>> Spring has a concept called "transaction suspension" which allows you
>> to detach a transaction from a thread. This is primarily used to
>> execute a separate transaction on the same thread (and later resume
>> the original transaction), but this probably can also be used to
>> reattach the transaction to a different thread. So, by googling for
>> "transaction suspension" you may be able to find some information
>> about how to do this.
>
> _Spring_ has this concept? Err, no, not exactly. This is a standard JTA
> operation which is documented in the JTA spec**. Anyone who uses
> transactions in Java ought to read and know this specification (it's not
> very big). At the very least they ought to have looked up the documentation
> of the API classes, Transaction and TransactonManager.
>
> Spring may well have wrapped this up in their own API to make it look like
> they have done some work instead of just packaging someone else's
> implementation. That's business as usual for them.
>
> regards,
>
>
> Andrew Dinn
> -----------
> ** specifically you want:
> javax.transaction.Transaction javax.transaction.TransactionManager.suspend()
> javax.transaction.TransactionManager.resume(javax.transaction.Transaction
> transaction)
>

Re: @Transactional in another thead?

Posted by Andrew Dinn <an...@googlemail.com>.
On 02/16/2010 06:25 PM, Andreas Veithen wrote:
> Spring has a concept called "transaction suspension" which allows you
> to detach a transaction from a thread. This is primarily used to
> execute a separate transaction on the same thread (and later resume
> the original transaction), but this probably can also be used to
> reattach the transaction to a different thread. So, by googling for
> "transaction suspension" you may be able to find some information
> about how to do this.

_Spring_ has this concept? Err, no, not exactly. This is a standard JTA 
operation which is documented in the JTA spec**. Anyone who uses 
transactions in Java ought to read and know this specification (it's not 
very big). At the very least they ought to have looked up the 
documentation of the API classes, Transaction and TransactonManager.

Spring may well have wrapped this up in their own API to make it look 
like they have done some work instead of just packaging someone else's 
implementation. That's business as usual for them.

regards,


Andrew Dinn
-----------
** specifically you want:
javax.transaction.Transaction javax.transaction.TransactionManager.suspend()
javax.transaction.TransactionManager.resume(javax.transaction.Transaction transaction)

Re: @Transactional in another thead?

Posted by Andreas Veithen <an...@gmail.com>.
Spring has a concept called "transaction suspension" which allows you
to detach a transaction from a thread. This is primarily used to
execute a separate transaction on the same thread (and later resume
the original transaction), but this probably can also be used to
reattach the transaction to a different thread. So, by googling for
"transaction suspension" you may be able to find some information
about how to do this.

Andreas

On Tue, Feb 16, 2010 at 19:03, Daniel Kulp <dk...@apache.org> wrote:
>
> This is definitely a Spring thing and you would probably need to ask on the
> Spring forums.   Basically, the transaction information is held in a
> ThreadLocal someplace and if you flip threads, the transaction information is
> no longer available on that thread.   There MAY be a way in spring to copy the
> transaction information to a new thread, but I'd have no idea how to do it.
> You would need to ask them.
>
> Dan
>
>
> On Mon February 15 2010 2:02:45 pm Wadi Jalil Maluf wrote:
>> Hi all,
>>           Im using Spring @Transactional anotation to handle
>> trasnactions. The thing is that I have a Service that opens another
>> thread and later calls a method using @Transactional . Whe I do that I
>> get a TransactionRequired exception, does anyone know how ca I deal with
>> @Transactional and multiple threads?Why is this a problem, am I missing
>> something?Any help would be appreciatted,
>> Thanks in advance,
>> Ernest
>>
>>
>> __________ Información de ESET Smart Security, versión de la base de firmas
>> de virus 4869 (20100215) __________
>>
>> ESET Smart Security ha comprobado este mensaje.
>>
>> http://www.eset.com
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>

Re: @Transactional in another thead?

Posted by Daniel Kulp <dk...@apache.org>.
This is definitely a Spring thing and you would probably need to ask on the 
Spring forums.   Basically, the transaction information is held in a 
ThreadLocal someplace and if you flip threads, the transaction information is 
no longer available on that thread.   There MAY be a way in spring to copy the 
transaction information to a new thread, but I'd have no idea how to do it.   
You would need to ask them.

Dan


On Mon February 15 2010 2:02:45 pm Wadi Jalil Maluf wrote:
> Hi all,
>           Im using Spring @Transactional anotation to handle
> trasnactions. The thing is that I have a Service that opens another
> thread and later calls a method using @Transactional . Whe I do that I
> get a TransactionRequired exception, does anyone know how ca I deal with
> @Transactional and multiple threads?Why is this a problem, am I missing
> something?Any help would be appreciatted,
> Thanks in advance,
> Ernest
> 
> 
> __________ Información de ESET Smart Security, versión de la base de firmas
> de virus 4869 (20100215) __________
> 
> ESET Smart Security ha comprobado este mensaje.
> 
> http://www.eset.com

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog