I have a Service class such as following:
@Transactional
@Component(value = "userServiceImpl")
public class UserServiceImpl implements UserService
{
@Autowired
private UserDao userDaoiBatis;
public boolean X()
{
// Call UserDao.A and UserDao.B in transaction.
}
}
And a Dao class such as following:
@Transactional
@Component(value = "userDaoiBatis")
public class UserDaoiBatis extends SqlMapClientDaoSupport implements UserDao
{
@Autowired
private void injectSqlMapClient(SqlMapClient sqlMapClient)
{
setSqlMapClient(sqlMapClient);
}
@Override
public boolean A()
{
throw new RuntimeException("Not implemented");
}
@Override
public boolean B()
{
throw new RuntimeException("Not implemented");
}
}
How can I call UserDaoiBatis.A() and UserDaoiBatis.B() as part of a transaction in userServiceImpl.Z() ???
What you have setup looks correct. The transaction will be started by
UserServiceImplthen both calls toUserDaoiBatiswill inherit the existing transaction (@Transactionaldefaults to REQUIRES propagation). You can confirm this by enabling debug level logging on theAbstractPlatformTransactionManagerclass.Note that with
A()throwing an exception, the tx will rollback.