I was trying to understand an existing code and then I found the use of @Transactional(read-only = true)
in the code.
I went through this link.(Spring @Transactional read-only propagation).
But I cannot relate it to my case.
I am using Hibernate as the ORM tool and uses HibernateTransactionManager
to manage the transactions.
As per my understanding, code is trying to commit some data to a set of tables and before that I need to fetch some data from two master tables.
If the master table query returns nothing, an exception should be thrown.
Following is the skeleton of the entire code.
@Transactional
persistSomeData(int id){
MasterData masterData = getMasterData(id);
if(null == masterData)throw new Exception("No Master data found !!");
persistChildTableData(masterData.someField);
}
@Transactional(read-only = true)
MasterData getMasterData(int id){
//query to get the masterdata using id
}
I want to know the significance of read-only = true
in the getMasterData()
.