即使在使用@transactional 注释之后,如何解析 spring 中的 'No transaction is currently active'?
How to resolve 'No transaction is currently active' in spring, even after using @transactional annotation?
//--Service class--
@Service
public class myService implements myInterface {
@Autowired
private MyDao myDao;
//some code
myDao.updateMethod(/*some arguments*/);
//some code
}
//--Dao class--
@Repository
public class MyDao {
@Transactional(transactionManager = sample_a)
public void updateMethod(/*some arguments*/){
newUpdateMethod(/*some arguments*/);
}
@Transactional(transactionManager = sample_a)
public void newUpdateMethod(/*some arguments*/){
/* Actual call to DB taking place */
}
}
当我从服务 class 调用 updateMethod 时,它给出了与事务相关的异常 - InvalidDataAccessApiUsageException - 当前没有事务处于活动状态,我在使用 @Transactional
正确的路?我还在某处读到 @Transactional
should not be used in class with @Repository
annotation,但我在 Dao class 中有其他方法 @Transactional
并且它们工作正常.
以上代码运行良好,问题出在事务管理器中。我正在使用不同的事务管理器。我用来更新数据的 table 在不同的数据库中。
//--Service class--
@Service
public class myService implements myInterface {
@Autowired
private MyDao myDao;
//some code
myDao.updateMethod(/*some arguments*/);
//some code
}
//--Dao class--
@Repository
public class MyDao {
@Transactional(transactionManager = sample_a)
public void updateMethod(/*some arguments*/){
newUpdateMethod(/*some arguments*/);
}
@Transactional(transactionManager = sample_a)
public void newUpdateMethod(/*some arguments*/){
/* Actual call to DB taking place */
}
}
当我从服务 class 调用 updateMethod 时,它给出了与事务相关的异常 - InvalidDataAccessApiUsageException - 当前没有事务处于活动状态,我在使用 @Transactional
正确的路?我还在某处读到 @Transactional
should not be used in class with @Repository
annotation,但我在 Dao class 中有其他方法 @Transactional
并且它们工作正常.
以上代码运行良好,问题出在事务管理器中。我正在使用不同的事务管理器。我用来更新数据的 table 在不同的数据库中。