简体   繁体   English

在EJB 2.0中成功交易时调用方法

[英]Call a method on successful transaction in EJB 2.0

I have been working with ejb 2.0 for past 2 years on my application and suddenly stuck with a problem where I just want to call a method before and after transaction to database. 我在应用程序上使用ejb 2.0已有2年了,突然遇到一个问题,我只想在事务处理到数据库之前和之后调用方法。

I am sure EJB 3.0 has interceptors to deal with this problem but any idea about EJB 2.0 that how to achieve it. 我确信EJB 3.0具有拦截器来处理此问题,但是有关EJB 2.0的任何想法都知道如何实现。

Your bean can implement the interface SessionSynchronization . 您的bean可以实现SessionSynchronization接口。 I think it's pretty old and was already in EJB 2.x. 我认为它已经很旧了,并且已经在EJB 2.x中。

Alternatively, there's javax.transaction.Synchronization and javax.transaction.TransactionSynchronizationRegistry that you can use to register callback. 另外,也可以使用javax.transaction.Synchronizationjavax.transaction.TransactionSynchronizationRegistry来注册回调。

This question discusses differences between the two; 这个问题讨论了两者之间的差异。 it seems to be unreliable to use SessionSynchronization for SLSB. 对于SLSB使用SessionSynchronization似乎是不可靠的。 I would recommend to read the relevant parts of the spec to understand precisely how they work. 我建议阅读规范的相关部分,以准确了解它们的工作方式。

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

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