05-29-2017 12:00 PM
As a general practice, when developing Webscripts that only read data:
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
05-30-2017 04:08 AM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.