EJB Local includes Remote

75 views Asked by At

Let's assume we are using EJB3 and our session bean uses/implements Local Interface L and Remote Interface R.

@Local
public interface L {
 abstract void localMethod();
}

@Remote
public interface R {
  abstract void remoteMethod();
}

My Question 1:

can a local client also make use of remoteMethod?

My Question 2:

is it good practice to extend the local interface with the remote interface?

@Local
public interface L extends R {
...
}
1

There are 1 answers

0
Brett Kail On
  1. It's not clear what you mean "a local client". If you have a client in the same process, then it can use both L and R, but you have to lookup/inject them separately: you cannot lookup L, cast to R, and call remoteMethod.

  2. I would stop short of calling it a "good" practice. Parameters and return values of the methods on the remote interface will be pass-by-value but the parameters and return values of the methods on the local interface will be pass-by-reference. That said, if your EJB and its clients are aware of this caveat, then you can get much better performance by using the local interface when possible.