Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Tuesday, June 17, 2008

Transaction Attributes in Spring

In spring, Transaction attribute defines the rules for applying policies on methods. It can have one or more parameters from the following:
1. Propagation behavior
2. Isolation level
3. Read only hints
4. Transaction timeout period

Propagation behavior is used to define the transaction boundaries.. Its very much inherited from EJBs transaction management. ADF Bounded task flow do have similar stuff. Spring has a much richer set of propagation behavior managment compare to EJBs. In brief these are:

a)PROPAGATION_MANDATORY: signifies method must be running in a transaction
b)PROPAGATION_NESTED: this is not in EJBs. It talks about creating a new child transaction if a transaction is already existing.
c)PROPAGATION_NEVER: signifies that method should not be running in a transactional context.
d)PROPAGATION_NOT_SUPPORTED: same as above but above will throw exception in case it happens. This will suspend the transaction for the duration the method runs.
e)PROPAGATION_REQUIRED: there must be a transactional context present if not there it will create a new.
f)PROPAGATION_REQUIRES_NEW: there should not be any pre-existing transactional context. it will create a new.
g)PROPAGATION_SUPPORTS: it signifies that it does not need a transactional context but if there is any it doesnt mind.

Isolation level:
This has something to do with the concurrency control. When multiple transactions are running they may cause dirty reads, non repeateable reads and phantom reads. Spring provides various options depending upon the tolerance of the business use case you can use one. these are:
a)ISOLATION_DEFAULT: it uses the undelying datastore isolation policy.
b) ISOLATION_READ_UNCOMMITTED: it allows to read the data even when there are uncommited rows thus could lead dirty read or non repeateable read or phantom reads.
c) ISOLATION_READ_COMMITTED: only commited rows are read but still it may cause non-repeateable read or phantom reads.
d) ISOLATION_REPEATABLE_READ: as name suggests prevents dirty read as well as non-repeateable issues but phantom reads could be there.
e)ISOLATION_SERIALIZABLE: this brings the ACID (Atomicity, concurrancy, isolation and durability) compliance. But it is very strict and restricted so could be a performace issue.

Read only hints: Sometimes there is a requirement to just read the data from the datastore. in that case providing this attribute can make a good performance boost as datastore can apply some optimizations. But this can be done by datastore when a new transaction started. so this attribute makes sense only if propagation propety is PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, or PROPAGATION_NESTED.

Transaction Timeout: This is just a way to prevent deadlocks or unresponsive threads or resource locks in the system. You can specify some timeout that will kill the transaction after the specified timeout period. again it starts when a new transaction begins so it makes sense if propagation is PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, or PROPAGATION_NESTED.

13 comments:

Anonymous said...

I wonder why people come up with blogs that just replicate the docs that are already out there...do you make money with these blogs with AdSense or anything like that...I do not see any reason otherwise..show some originality...the whole outsourced industyr is so plagiarized...

Unknown said...

Well there is one more reason.. That is reviewing loud their learnings. People go through these who are already good and do some add on or suggest the corrections.

New comer are coming every moment and they sometimes needs very basic or a brief of what is available in depth on net.

Soggadu said...

Agreed!!!..Vivek, When I try to google on net, I found your article first...Tht makes sense

Unknown said...

Thanks soggadu

Anonymous said...

And a new bee will get screwed if some information changes on the source because you were too busy to update this blog.

This is pure plagiarism.

Unknown said...

Blogs are never meant to be a medium of constant update. They are just to express your feelings, learnings and what ever comes to your mind (not necessarily be original).

So, its just the responsibility of the searcher to looks at least the date of blog post to decide if it could be too old to refer.

Tapas said...

hi Vik, I found ur blog is really helpful .thanks for posting and keep posting some new topic like this.

Anonymous said...

Amiable dispatch and this enter helped me alot in my college assignement. Thank you as your information.

Patrick said...

New comer are coming every moment...that is damn true! Your blog is helpful as I waste quite some time to search through official docs from Spring, can't really find something I need(what exactly you are blogging)

Anonymous said...

Thanks a lot for the quick overview. I find it useful. I usually create summaries myself and post it locally for reference, this is a good short one. Thanks again

Anonymous said...

i have to use two non xa Datsource strictly, which transaction attributes will be suitable ?thanks in advance.

yasha said...

Great Summary! Thanks Vik. Please ignore people who discourage you.

Anonymous said...

good explanation... -J