Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

TransactionTemplate or @Transactional?

David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

Should I be using TransactionTemplate directly, or using @Transactional, when accessing ActiveObjects in an add-on?

The ActiveObjects doco mentions @Transactional, but the Stash SSH plugin uses TransactionTemplate, and I can't remember why.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

Hi David,

From a plugin you should be using TransactionTemplate (imported from SAL). It will do all the necessary plumbing to ensure your DB operations are performed transactionally.

As you mentioned the SshKeyServiceImpl from the SSH plugin is a good example of how to use it.

cheers,

Tim

David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

I suspected that was the case. So the approach described by the ActiveObjects doco is not right? It suggests using:

com.atlassian.activeobjects.external.TransactionalAnnotationProcessor

TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

Actually digging into it a bit further looks like @Transactional would work too, though with slightly more overhead. Services marked with @Transactional will end up being wrapped in a dynamic proxy that uses TransactionTemplate (provided you have the right bean post-processors wired into your plugin), so either method is probably ok.

To be honest, I'd still be going with TransactionTemplate for the sake of simplicity and not tying yourself further to the AO library.

David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

You make a good point about independence from the AO library. Thanks mate.

TAGS
AUG Leaders

Atlassian Community Events