This is a very modest question.
There are several articles that indicate that database transactions should always be used, even for simple read operations. Here's an arbitrary example that makes a lot of sense to me: http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions The Hibernate documentation itself also says:
Always use clear transaction boundaries, even for read-only operations.
OK, it seems clear enough. This has always been my assumption, namely: that since transactions will be applied implicitly at the database level in any case in all cases, it is probably best to always declare them explicitly.
Then I read other articles as follows: http://www.ibm.com/developerworks/java/library/j-ts1/index.html#never (note the callout). This article specifically states:
Never say never
At certain points in time, you can start a transaction for a database read operation, for example, by isolating read operations for consistency or by setting a certain transaction isolation level for a read operation. However, these situations are rare in business applications, and if you do not encounter one, you should avoid starting a transaction for database read operations, since they are not needed and can lead to database locks, poor performance, and low bandwidth.
A bit about dead ends and poor bandwidth also makes sense to me.
Conflict advice at the lowest level. This is normal; as a modest application developer, I can come up with my mind here, I think: I prefer the previous advice, perhaps seeing that if this ORM / database combination provides better transaction-free performance in certain critical cases. Please correct me if I am wrong.
Now I am returning to the XA application and transaction server area.
If I have an EJB method that performs read-only operations, is it good practice to always declare it transactional (following the spirit of the Hibernate advice above)? Or marking it as @TransactionAttribute(TransactionAttributeType.SUPPORTS) doesn't mean much about the database transaction strategy next to the metal?
What I mean, an EJB transaction (JTA) occurs at the application server level. Perhaps it could be (I don't know) that when a Java EE application server interacts with Hibernate, Hibernate will always apply explicit transactions at the database level, regardless of the transaction policy at the application level. Thus, the Hibernate articles I cited here may not apply to JTA transactions at the server application level - perhaps it is good practice to label read-only methods as @TransactionAttribute(TransactionAttribute.SUPPORTS) instead of REQUIRED .
What do people think here? All pointers are welcome - even basic information.