-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Is it legal to place @Transactional in View Model?
And where is the best location to place that annotation?
Thx
Yes i agree with Stephan
For a clean separation of the application layers you should separate the backend from the frontend. In my eyes the ViewModel is a special 'model' in the frontend and interacts with the the backend methods.
@Transactional should be placed on the 'service' methods who calls one or more 'DAO methods'. In that case the transaction is wrapped around all your several needed dao methods which is often common for more complex crud handling. So it's ensured that all is saved or nothing if an error occurs.
@Transactional
public void saveMyWholeBusinessStuff(){
getDAO1().save(myFirstBeanToSave);
getDAO2().save(mySecondBeanToSave);
getDAO3().update(myThirdStatisticBean);
}
best Stephan
You can check here
Asked: 2013-02-28 04:48:01 +0800
Seen: 30 times
Last updated: Feb 28 '13