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

3

7

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?

Registered answered 24/5, 2017 at 13:26 Comment(0)
B
10

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.

Bertero answered 24/5, 2017 at 14:30 Comment(1)
Note the may improve. There are things that affect performance far more than whether a transaction is on or not, so it's not a very smart idea to start putting that everywhere as a micro-optimization.Fyrd
C
2

This article says:"No, it doesn't make sense to use the NOT_SUPPORTED transaction propagation for read-only queries". It's written Vlad Mihalcea who is a JPA expert.

Does TransactionAttributeType.NOT_SUPPORTED make sense for retrieving entities?

Canasta answered 4/12, 2019 at 9:33 Comment(0)
T
1

NOT_SUPPORTED is useful if there is a processing that would cause an exception if invoked with transaction context. For example invoking stored procedure containing DDL code withing context of XA processing will cause an exception to occur. If changing stored procedure is not an option use NOT_SUPPORTED attribute as work around and suspend the transaction prior to invocation of method containing problematic stored procedure.

If transaction roll back is allowed in read only transaction use SUPPORTS , if transaction roll back is not allowed in read only transaction use NOT_SUPPORTED.

Thrasonical answered 12/6, 2017 at 17:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.