See: http://www.ibm.com/developerworks/cn/java/j-ts2.html
I. Transaction Model:
1. Local Transaction Model
JDBC local transaction,
Dbconnection. setautocommit (true );
In the local transaction model, transactions are managed and maintained by the underlying database (DBMS) or message provider (Message provider). From the developer's perspective, you only need to manage connections) you do not need to manage transactions. The local transaction model works well in simple update operations of small projects, but in more complex application scenarios, one problem is that it is difficult to coordinate resources in an Xa global transaction. Generally, the EJB project does not use such a transaction model.
2. Programmatic Transaction Model
Bean management transactions in EJB
In the programming transaction model, developers no longer develop for connections but transactions. In the EJB project, this type of transaction model is embodied in bean-managed transactions (bean-managed transactions -- BMT). Generally, usertransaction is obtained through sessioncontext or JNDI. The programmatic transaction model has a major architectural limitation: we cannot transmit the transaction context (transaction context) between two beans that use the programmatic transaction mode ). However, we can pass the transaction context of an EJB or client that uses the programmatic transaction model to an EJB that uses the declarative transaction model. Therefore, in general, we only use the programmatic transaction model in the client that calls EJB.
Obtain the platform Transaction Manager in spring, commit () or rollback ()
3. Declarative Transaction Model
In the declarative transaction model, containers manage and maintain transactions, which means that developers do not need to write Java code to start or commit a transaction, instead, a certain "Declaration" is used to tell the container how to manage transactions. We can declare the container through the ejb-jar.xml configuration file, or use annotations or deployment descriptors to declare the use of transactions. In EJB, the declarative transaction model is reflected in the container-managed transactions-CMT ).
Container managed transactions(CMT)
Spring usage@TransactionalAnnotations, while EJB 3.0 uses@TransactionAttributeAnnotations. When the declarative transaction model is used, the container will not automatically roll back the transaction for the detected exceptions. The developer must specify where the exception occurred and when to roll back the transaction. In spring framework, you can use@TransactionalComment onrollbackForAttribute to specify it. In EJB, you callSessionContextOnsetRollbackOnly()Method to specify it.
In most cases, we use a declarative transaction model (CMT) when implementing ejbs, while a programmatic transaction model is used in client code that calls these ejbs.
Ii. Transaction Policy
Client orchestration transaction policy
API layer transaction policy
High concurrency transaction policy
High-speed processing transaction policy