Originally posted by Kris Reid: Why can't statless bens implement sessionSynchronization? Can BMT Session beans implement sessionSynchronization? It would be pointless but can they? Can EntityBeans implement sessionSynchronization?
1.) Stateless beans cannot implement sessionSynchronization because transactions in stateless session beans are not allowed to span multiple method calls. As soon as a method returns, the transaction is over. Begin/Commit is governed by the scope of the method. There is no more sense to call the sessionSynchronization methods. 2.) They can (im not sure) but might not be called by the container since it expects the bean provider to explicitly call begin and commit. 3.) Entitiy beans have onLoad() and onStore() methods instead of the sessionSynchronization methods. I'm not sure if implementing is legal. I doubt it.
By allowing stateless session beans to implement SessionSynchronization, we're actually implying that session beans can maintain state across transactions, which is not true. Hence, it is not allowed.
Can BMT Session beans implement SessionSynchronization? It would be pointless but can they?
You can't. Because by having BMT, you know exactly when you're starting & ending the transactions. The exact boundaries of the transactions are made known to you. Hence, you don't have to rely on implementing the SessionSynchronization interface.
Can EntityBeans implement SessionSynchronization?
As of EJB 2.0, entity beans can only be of CMT type. As pointed out by Paul, you've the benefits of ejbLoad & ejbStore. Also, the name of the interface sortof indicated that its meant for session beans only.