Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB 3 Transaction attribute for read only method

I have a method that returns lot of data, should I use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) for this method. The method perform a JPA query an loads the full content of a table (about 1000 rows).

like image 465
Dani Cricco Avatar asked Aug 05 '09 13:08

Dani Cricco


2 Answers

The client to this method - is that already in a transaction? When you use NotSupported the caller transaction will be suspended. If not I would say, just put Never as the transaction type. Never is better since callers know they are not supposed to call this method from inside a transaction. A more straight forward contract.

We always use Never for methods that do more processing so that developers are aware right off the bat not to call if they are involved in a transaction already. Hope it helps.

like image 151
OpenSource Avatar answered Sep 27 '22 15:09

OpenSource


I would care to disagree as it seldom happens that user is not in a transaction in almost all the systems. The best approach is to use NOT SUPPORTED so that the transaction is suspended if the caller is in any transaction already. NEVER is troublesome unless you have a series of calls which are all in NO TRANSACTION scope. In short, NOT SUPPORTED is the type one should use.

like image 29
Hammad Dar Avatar answered Sep 27 '22 16:09

Hammad Dar