How to use EJB transaction properties to control the scope of a transaction

Source: Internet
Author: User
Tags require

The EJB transaction attribute can be one of several values:

Required,requiresnew,mandatory,notsupported,supports,never.

1, Required

If the customer runs in an EJB transaction, and the method in the EJB is invoked, the method runs in the EJB transaction of the client. If the client is not associated with an EJB transaction, the container starts a new EJB transaction before it runs the method. The required attribute is suitable for most EJB transactions, and it is recommended that it be set to default, at least in the development phase. EJB transaction attributes are declarative and can be easily modified later.

2, RequiresNew

If the client is running in an EJB transaction and the method in the EJB is invoked, the container takes the following actions:

(1) Suspend client EJB transaction

(2) Start a new EJB transaction

(3) Delegate the call to the method

(4) After the execution of the method, reply to the client EJB transaction

If the client is not associated with an EJB transaction, the container starts a new EJB transaction before it runs the method. If you ensure that the method always runs in a new EJB transaction, you should use the RequiresNew property.

3, mandatory

If the client is running in an EJB transaction and the method in the EJB is invoked, the method runs in the client EJB transaction. If the client is not associated with an EJB transaction, the container throws a transactionrequiredexception. If the method in the EJB must use the client's EJB transaction, the mandatory attribute should be used.

4, NotSupported

If the client is running in an EJB transaction and the method in the EJB is invoked, the container suspends the client EJB transaction and then replies to the client EJB transaction after the method is called. If the client is not associated with an EJB transaction, the container does not start the EJB transaction until the method is run. This property can be considered for methods that do not require an EJB transaction. EJB transactions require a certain amount of overhead, notsupported properties can improve performance.

5, Supports

If the client is running in an EJB transaction and the method in the EJB is invoked, the method runs in the client's EJB transaction. If the client is not associated with an EJB transaction, the container does not start a new EJB transaction before it runs the method.

6, Never

If the client is running in an EJB transaction and the method in the EJB is invoked, the container throws a RemoteException exception. If the client is not associated with an EJB transaction, the container does not start a new EJB transaction until it runs the method.

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.