Spring managed transactions without @Transactional annotation

后端 未结 4 523
后悔当初
后悔当初 2020-12-14 02:36

I\'m using Spring annotations to manage my transactions like so:

@Transactional(readOnly = true)
public class AlertServiceImpl implements AlertService {

            


        
4条回答
  •  佛祖请我去吃肉
    2020-12-14 03:16

    Without the annotation, you lose the advantages of the transactions like the rollbacks.

    With the @Transactional annotation you are doing more than one database operation, like many inserts and one fails, all the operations in the transaction can rollback to give consistency to your data.

    That is also why it's recommended to put the annotation in the services not in the DAOs.

提交回复
热议问题