javahibernateejbejb-3.1jta

Is it good to make TransactionAttributeType.NOT_SUPPORTED if method doesn't persist any entity


If I have nested bean methods which just fetching data from the database. (i.e GET API). So will it be beneficial to mark all bean methods as TransactionAttributeType.NOT_SUPPORTED? Will it help in increase in performance as JTA is not managing any transaction for this?


Solution

  • This is exactly the purpose of using NOT_SUPPORTED, to increase performance. Infact as stated by Oracle:

    NotSupported Attribute

    If the client is running within a transaction and invokes the enterprise bean’s method, the container suspends the client’s transaction before invoking the method. After the method has completed, the container resumes the client’s transaction.

    If the client is not associated with a transaction, the container does not start a new transaction before running the method.

    Use the NotSupported attribute for methods that don’t need transactions. Because transactions involve overhead, this attribute may improve performance.

    So, it is a perfect fit for all the select or find business methods, which purpose is maybe to fill a data table on screen.