This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Implements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Implements" Watch "Implements" New topic


S Babs

Joined: Apr 16, 2003
Posts: 18
Why Stateless Session Bean class shouldn't implement Remote interface, since it defines all the business logic methods mentioned in the beans Remote Interface?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
There are a few reasons...
1) Your bean implementation is NOT an EJBObject. It is the implementation of the logic used in the EJBObject created by the Container, however it is not one itself.
2) If your bean were you implement its remote interface then you would have to provide an implementation for the other methods in EJBObject that your remote interface extends. These could be empty bodies but ultimately these methods should not be in your bean implementation class.
3) Your remote interface declares that RemoteExceptions can be thrown. You do not want your bean implementation declaring that it throws RemoteExceptions. It is allowed by the spec (for backwards compatability) but heavily discouraged.
4) Stronger type safety. You don't want the possibility of passing an instance of your bean implementation when what is really needed is an EJBObject. Again your bean instance is NOT an EJBObject.
That said... there is nothing preventing you from doing just as you said, it is just considered bad practice. A better solution is to define a common interface for both the remote interface to extend and the bean instance to implement. In fact this is a widely used idea called a business interface.
Suri Babs
Ranch Hand

Joined: Mar 27, 2003
Posts: 50
Understand following and let me know if any answer for this. Consider the following bean as Stateless Session bean.
// Bean home interface
public interface TestHome extends EJBHome {
// create method
// Bean Remote interface
public interface Test extends EJBObject {
// Declare bussiness methods
// Now bean class
public class TestBean implements SessionBean{
// callback methods
// and business methods
As you can see that bean class implementing SessionBean, but my question is according rules of java, the "TestBean" also implement the "Test" remote interface like below
public class TestBean implements SessionBean, Test {
// callback methods
// business methods
since it implements all the business logic methods declared in the "Test" remote interface.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
I just answered your question above. It is technically possible but it is highly discouraged...
I agree. Here's the link:
subject: Implements
It's not a secret anymore!