spring-integration - Spring Integration (DSL):在同一个事务中运行两个 JPA 查询
问题描述
如何让两个 JPA 查询在同一个事务中运行?
请参见下面的示例。如果第二个查询失败,我希望回滚第一个查询。
@Bean
IntegrationFlow dbFlow() {
return IntegrationFlows.from("poiChannel")
.routeToRecipients(r -> r
.recipientFlow(
(f) -> f.handle(Jpa.outboundAdapter(entityManagerFactory)
.jpaQuery("delete from PointOfInterest"),
e -> e.transactional()
)
)
.recipientFlow(
(f) -> f.handle(Jpa.outboundAdapter(entityManagerFactory)
.entityClass(PointOfInterest.class),
e -> e.transactional(true)
)
)
)
.get();
}
解决方案
好吧,看来我只需要将transactional()
命令上移一级即可routeToRecipients()
。
@Bean
IntegrationFlow dbFlow() {
return IntegrationFlows.from("poiChannel")
.routeToRecipients(r -> r
.recipientFlow(
(f) -> f.handle(Jpa.outboundAdapter(entityManagerFactory)
.jpaQuery("delete from PointOfInterest")
)
)
.recipientFlow(
(f) -> f.handle(Jpa.outboundAdapter(entityManagerFactory)
.entityClass(PointOfInterest.class)
)
)
.transactional()
)
.get();
}
推荐阅读
- bash - 当 FreeBSD 上温度过高时,Bash 脚本会发出哔哔声
- arrays - reactjs ref 仅适用于数组中的最后一个元素
- javascript - 如何显示画廊的第一张图片?
- powershell - Powershell - 在 foreach 中检查变量的值 - 如果没有值,则记录其他输出
- c++ - 如何在不超出范围的情况下从字符串中删除非字母字符
- c# - XSLT 无效令牌导致 XML 文档无效
- excel - Excel 在打开其他电子表格时运行缓慢
- c# - 无法验证和上传多张图片
- c++ - 预期的 ”;” 在数字常量之前
- c++ - 将空数组传递给函数,填充数组并获取值