简体   繁体   English

Spring 即使对于未经检查的异常,事务也不会回滚

[英]Spring Transaction is not rolling back even for unchecked Exceptions

在此处输入图像描述

in the above code i have used hibernate with mysql and the hibernate session is managed by SpringSessionContext (that'y am using sessionFactory.currentSession class under transactional boundary) in the above code i have used hibernate with mysql and the hibernate session is managed by SpringSessionContext (that'y am using sessionFactory.currentSession class under transactional boundary)

the below image (dao layer) is straight forward use case but the exception is not rolled back i have called this method from simple service layer (ie service layer is calling dao layer for CRUD operation) i learned about spring proxy mechanism on transaction management in this case this below image class is implementation of Dao interface so spring will create a proxy bean using Jdkdynamic proxy and this method is called from service layer (non transactional class but the expectation was data should not be persisted exception should rollback but it was persisted in db下图(dao 层)是直截了当的用例,但异常没有回滚在这种情况下,下图 class 是 Dao 接口的实现,因此 spring 将使用 Jdkdynamic 代理创建代理 bean,并且从服务层调用此方法(非事务性 ZA2F2ED4F8EBC2CBB4C21A29DC40AB61D 应该回滚但期望数据不应该持久化但预期数据应该是持久化异常D b

Hibernate persists dirty objects after the whole transaction process is completed. Hibernate 在整个事务过程完成后持久化脏对象。 You should examine the first input method to the last method flow.您应该检查第一个输入法到最后一个方法流程。 Hibernate persisting operation is not processed when the save function is called.调用 save function 时不处理 Hibernate 持久化操作。 It stores into a buffer map, and after the transaction completes, it will be processed.它存储到缓冲区 map 中,事务完成后,将被处理。 Are there any transactions or try-catch blocks in your flow?您的流程中是否有任何交易或 try-catch 块?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM