Social Sciences, asked by danielsmb, 11 months ago

Describe the essentially of transaction management and explain how transaction management works in distributed platforms?

Answers

Answered by killer555
0

Answer:

Most of the time developers give little importance to transaction management. As a result, lots of code has to be reworked later or a developer implements transaction management without knowing how it actually works or what aspect needs to be used in their scenario.

An important aspect of transaction management is defining the right transaction boundary, when should a transaction start, when should it end, when data should be committed in DB and when it should be rolled back (in the case of exception).

The most important aspect for developers is to understand how to implement transaction management in an application, in the best way. So now let's explore different ways.

Ways of Managing Transactions

A transaction can be managed in the following ways:

1. Programmatically manage by writing custom code

This is the legacy way of managing transaction.

EntityManagerFactory factory = Persistence.createEntityManagerFactory("PERSISTENCE_UNIT_NAME"); EntityManager entityManager = entityManagerFactory.createEntityManager(); Transaction transaction = entityManager.getTransaction() try { transaction.begin(); someBusinessCode(); transaction.commit(); } catch(Exception ex) { transaction.rollback(); throw ex; }

Pros:

The scope of the transaction is very clear in the code.

Cons:

It's repetitive and error-prone.

Any error can have a very high impact.

A lot of boilerplate needs to be written and if you want to call another method from this method then again you need to manage it in the code.

2. Use Spring to manage the transaction

Spring supports two types of transaction management:

Programmatic transaction management: This means that you have to manage the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain.

Declarative transaction management: This means you separate transaction management from the business code. You only use annotations or XML-based configuration to manage the transactions.

Similar questions