[英]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.