EJB 3 Transaction attribute for read-only method

I have a method that returns a lot of data if I use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) for this method. The method executes a JPA request, loads the full contents of the table (about 1000 rows).

+4
source share
2 answers

Is the client of this method already in the transaction? When you use NotSupported, the caller's transaction will be suspended. If I didn’t say just put Never as a transaction type. It is never better, as callers know that they should not call this method from within the transaction. More direct contract.

We always use Never for methods that do more processing, so that developers know right away, so as not to call if they are already involved in a transaction. Hope this helps.

+3
source

I would like to disagree with the fact that it rarely happens that a user is not in a transaction on almost all systems. The best approach is to use DOES NOT SUPPORT a transaction to be suspended if the caller is already in a transaction. NEVER be troubling if you do not have a series of calls, all of which are not in the OPERATION zone. In short, the type to be used is NOT SUPPORTED.

+2
source

All Articles