Spring managed transactions without @Transactional annotation

后端 未结 4 525
后悔当初
后悔当初 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:03

    In your scenario your DAO will execute without transaction, most probably with auto-commit.

    If you want to avoid this kind of mistake in future and require all your services to run in transaction you can protect DAO layer with following @Transactional annotation:

    @Transactional(propagation = MANDATORY)
    public class HibernateAlertDAO extends HibernateDaoSupport implements AlertDAO {
       ...
    }
    

    This annotation will require service layer to declare transaction and will throw exception otherwise.

提交回复
热议问题