Role of "READ_ONLY" transactions vs no transaction

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
davidraines
Active Member

Role of "READ_ONLY" transactions vs no transaction

As a general practice, when developing Webscripts that only read data:

  • should should you specify "READ_ONLY" transactions in the webscript's configuration, or should you specify no transactions required?  
  • Is it safe to attempt to read data from a "nodeService" or other Alfresco Service Registry object without first creating a transaction?

I know that in Hibernate / JDBC, the answer is to always create a transaction:

java - Why do I need Transaction in Hibernate for read only operation? - Stack Overflow 

But I'm not sure how concepts like that apply to Alfresco webscripts and Alfresco transactions.

VR,

David

1 Reply
afaust
Master

Re: Role of "READ_ONLY" transactions vs no transaction

It depends on two-three questions:

- Are you working with DB data? (Some Alfresco operations may not necessarily need to check any data managed in the DB)

- Are you performing more than two operations on Alfresco service API layer? (This includes loading data in JavaScript part of web script and then accessing the data again for rendering in FreeMarker)

- Do you need those operations to be consistent with regards to the DB state?

If all three questions are answered with yes then you should set the transaction on the web script layer. Otherwise Alfresco will automatically create small transactions when necessary, e.g. when you call services that deal with DB data (which are most of them).

I recommend always setting the transaction. It doesn't hurt performance and it is way more efficient to have one transaction than to potentially have multiple, automatically created ones.