简体   繁体   English

是否可以将整个@Transactional类的一个方法标记为非事务性的

[英]Is it possible to mark one method of an entire @Transactional class as non-transactional

I need to maintain the transaction manually in a method of a class which was marked as @Transactional. 我需要在标记为@Transactional的类的方法中手动维护事务。 If I try to do this now, an exception is being thrown (most probably because the transaction is being committed twice, once by me, and twice by the wrapper proxy). 如果我现在尝试这样做,则抛出异常(很可能是因为事务被提交两次,一次由我提交,两次由包装器代理提交)。 What do I need to do. 我需要做什么。

If this is not possible, then is there a way to get notified when a transaction was successfully committed (data in the DB and everything), so that I call another applciation, which relies on the same DB? 如果这是不可能的,那么有没有办法在成功提交事务时通知(数据库中的数据和所有内容),以便我调用另一个依赖于同一个数据库的applciation?

I hope you are using spring . 我希望你使用的是春天 If yes, then you can. 如果是,那么你可以。

Read this block of code from the API here . 请在此处阅读API中的代码块。 at section 10.5.6 Using @Transactional 在第10.5.6使用@Transactional

@Transactional(readOnly = true)
public class DefaultFooService implements FooService {

 public Foo getFoo(String fooName) {
// do something
}

// these settings have precedence for this method
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateFoo(Foo foo) {
 // do something
}
}

No, I don't believe this is possible. 不,我不相信这是可能的。 I believe if you create another thread and execute the code, it will be outside of the transaction though. 我相信如果你创建另一个线程并执行代码,它将在事务之外。 Be careful with that, because it can get dicey when you are creating additional threads and managing that yourself. 要小心,因为当你创建额外的线程并自己管理它时,它会变得有点冒险。

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

相关问题 延迟加载在Hibernate的非事务类/方法中工作 - Lazy loading working in non-transactional class/method in Hibernate 例外-非交易 - Exception - non-transactional 如何从事务方法调用非事务方法 - How to call non-transactional methods from a Transactional method 事务回滚后调用非事务方法 - Calling non-transactional method after transaction is rolled back 在另一个实例中从事务方法调用 spring 非事务方法时,事务是否得到传播? - When calling a spring Non-Transactional method from a Transactional Method in another instance, does the transaction get propagated? Spring Boot-从非事务性原因更新中校准事务性方法 - Spring Boot - caling transactional method from non-transactional cause update 如何重构@Transactional方法来拆分非事务性部分 - How do you refactor a @Transactional method to split out non-transactional parts 如何在相同和不同服务中调用@Transactional和non-Transactional方法时回滚事务? - How to rollback transaction on calling @Transactional and non-Transactional method in same and different Service? 非事务命令关闭OrienttDB中的数据库 - Non-Transactional Commands Closes Database in OrienttDB 非事务性jmsTemplate等待会话结束 - Non-transactional jmsTemplate waits for session end
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM