spring-boot - 休眠集成器+弹簧引导中没有发生回滚
问题描述
我们已经实现了休眠集成器,带有插入后和更新后事件监听器。能够成功拦截。在保存用事务注释包装的实体 A 时,事件侦听器被拦截,我们正在保存实体 B。到目前为止一切都很顺利。
但是现在,如果在第一个事务块上引发运行时异常,则实体 A 成功回滚,并且在数据库中看到实体 B 条目。没有实体 A,实体 B 就无法存在。
公共类 EntityEventListener 实现 PostInsertEventListener、PostUpdateEventListener {
Logger logger = LogManager.getLogger(EntityEventListener.class); private static AppService appService; @Autowired public void setYourServiceService(AppService transactionMetaDataService) { EntityEventListener.appService = appService; } /** * To handle any operations to be done post insert. */ @Override public void onPostInsert(PostInsertEvent event) { if(event.getEntity() instanceof EntityA) { try { //Which is annotated with @Transactional(TxType.REQUIRES_NEW) appService.create(event.getEntity()); } catch (Exception e) { } } } /** * To handle any operations to be done post update. */ @Override public void onPostUpdate(PostUpdateEvent event) { if(event.getEntity() instanceof WalletTransaction) { logger.info("calling update ....."); try { //Which is annotated with @Transactional(TxType.REQUIRES_NEW) appService.update(event.getEntity()); } catch (Exception e) { } } } @Override public boolean requiresPostCommitHanding(EntityPersister persister) { return false; } }
解决方案
推荐阅读
- android - 我无法为我刚刚发布的库的 gradle 依赖项声明导入
- python - 如何解决“没有返回 HttpResponse 对象”错误?
- sql-server - 将 SQL 过滤为一个值?
- python - 即使在安装模块后python中的ModuleNotFoundError
- python - 创建标准数据框以从 Pandas 中的其他数据框接收数据
- r - 使贝叶斯推理的定性数据量化
- node.js - Sequelize - 尝试使模型动态化
- spring - @EnableBinding @deprecated as of 3.2 有利于函数式编程模型,有什么方法可以说应用程序是像接收器应用程序一样
- java - 一次清除两个图表的导航堆栈
- javascript - 我的数字时钟 JavaScript 代码有什么问题?