http://static.children.org/children/docs/ 当前/vis/transaction.html#transaction-declarative-annotations
In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with @Transactional.
如果你预计自雇工作也与交易进行总结,则考虑采用AspectJ模式(见下表)。 在这种情况下,首先不会有代理;相反,目标类别将重现(即修改其分法),以便把“交易”变成任何一种方法的操作时间行为。
The @Autowired
reference B b
(inside class A
), is wrapped with a Spring AOP transaction-aware proxy.
当打电话到b.inner(>
时,你在交易通知中援引该编码,编号为@Transactional
。 因此,春天管理的交易已经开始。
When b.outer()
is called, it is also on a transaction-aware instance, but it is not @Transactional
. Thus a Spring managed transaction is not started.
Once you are inside the invocation of outer()
the call to inner()
is not going through the transaction-aware proxy, it is being invoked directly. It is the same as this.inner()
. Since you are invoking it directly, and not through the proxy, it does not have the Spring transaction-aware semantics.
由于没有开始交易,结果见<代码>《交易查询代码>。
Possible solutions include making the method outer()
@Transactional
.
@Transactional
public void outer() { inner(); }
或使整整整类“<代码>@Transactional。
@Transactional
@Component
class B {
@PersistenceContext
EntityManager em;