JTA Transaction Management

Source: Internet
Author: User

Divided

CMT container management transactions (recommended)

@ Transactionmanagement (transactionmanagementtype. Container) (Class-level annotation)

Container indicates that the CMT container manages transactions, and bean indicates BMT Management

@ Transactionattribute (transactionattributetype. required) (method-level annotation)

 

  Non-transactional context Client Transaction context Client
Required New transactions Classified as a superior transaction
Required_new New transactions Pending a superior transaction, new transaction
Supports Normal Classified as machine transaction
Mandatory Exception Classified as a superior transaction
Not_supported Normal Pending upper-level transactions
Never Normal Exception

The essence of supports is to support any transaction environment

Not_supported this attribute is only used in non-transactional automatic validation mode that supports MDB of the JMS provider

@ Resource // inject the EJB Context

Private sessioncontext context;

 

Context. setrollbackonly (); // an exception occurs during rollback.

BMT bean manages transactions, manages transactions by hard coding, and controls transaction boundaries.

(When usertransaction is used to manage a transaction, the upper-level transaction will be suspended)

@ Resource

Private usertransaction; // inject usertransaction

Usertransaction. Begin (); // start the transaction Boundary

Usertransaction. Commit (); // submit

Usertransaction. rollback (); // transaction boundary ends

Note: usertransaction can also be obtained through JNDI lookup.

And from sessioncontext context (EJB context), context. getusertransaction ()

Implementation exception class

@ Applicationexception (rollback = true)

// Rollback is false by default. If it is true, exception will be rolled back before being returned to the client.

Class XXX extends exception {}

All checked exceptions (except java. RMI. RemoteException) are expected to be application exception.
Java. RMI. RemoteException and non-checked exception are regarded as system exception

System exception is not directly transmitted to the client, but is saved as ejbexception by the container.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.