How does the return value of SessionContext.getBusinessObject () differ from the 'this' keyword used in the bean?

SessionContext.getBusinessObject () is described in the documents as follows:

Get an object that can be used to call the current bean through this business interface.

Parameters: businessInterface is one of the local business interfaces or remote business interfaces for this bean session.

Returns: A business object corresponding to this business interface.

Can't I use the 'this' keyword in Java instead to accomplish the same thing? How do they differ?

+6
java
source share
1 answer

The motivation here is that most EJB implementations run on proxies. You would not be too far thinking of it as AOP of an old school. The business interface is implemented by the EJB container, quite often using a simple java.lang.reflect.Proxy, and this object is passed to everyone on the system that requests ejb through an @EJB or JNDI search.

The proxy server connects to the container, and all its calls go directly to the container, which will pre-check security, start / stop / pause transactions, call interceptors, etc. etc., and then finally delegate the bean call and, of course, do any cleanup due to any exceptions - then finally pass the return value through the proxy to the caller.

Calling this.foo () directly or passing 'this' to the caller so that they can also make direct calls will skip all this and the container will be effectively cut out of the image. The getBusinessObject method (class) allows the bean instance to essentially receive the proxy server on its own, so that it can call its own methods and use the related container management services - interceptors, transaction management, security, etc.

+14
source share

All Articles