Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does @Transactional do? [duplicate]

I know this is probably a duplicate and, ironically, before I started reading here and there about it, I thought I knew what it was for (needless to say but I'll still say it, please correct me where I am wrong):

It relieves the programmer of having to use transaction.begin() and commit().
If you have a method that calls two DAO methods which normally would each have a transaction.begin and transaction.commit encompassing the real operations and call them it would result in two transactions ( and there might be rollback issues if the previous DAO method was supposed to be rolled-back too).

But if you use @transactional on your method then all those DAO calls will be wrapped in a single begin()- commit() cycle. Of course, in case you use @Transactional the DAOs must not use the begin() and commit() methods I think.

like image 250
osh Avatar asked Jul 10 '13 07:07

osh


People also ask

What does duplicate transaction mean?

Duplicate transactions are identical copies of an original transaction.

What does the @transactional annotation do?

Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans, as well as classes defined as managed beans by the Java EE specification, at both the class and method level where method level annotations override those at the class level.

What does duplicate transaction ID mean?

What does 'Duplicate Transaction ID' mean? This means that transaction was most likely already successful but the customer reloaded the checkout page and the same transaction was sent to the backend.

What does a duplicate transaction has been submitted?

The error indicates that a transaction request was submitted within a few minutes of a previous attempt with the same information. Authorize.Net identifies duplicate transactions by matching the data provided with the transaction.


1 Answers

You can handle your Transactions in two ways: Programmatically and Declarative.

When you're using transaction.begin and transaction.commit and ..., you are hanling your Transactions programmatically. This way you have more control on your Transaction boundaries but you will end up with lots of similar codes (Cross Cutting Concerns) scattered all over your project.

But in Declarative way, the codes that handle the Transactions are separated from your businesses logic and will not be scattered all over your project. It's one of the main concepts of Aspect Oriented Programming.

like image 93
chubock Avatar answered Oct 05 '22 23:10

chubock