This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Extending an EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Extending an EJB" Watch "Extending an EJB" New topic
Author

Extending an EJB

allison craig
Greenhorn

Joined: Dec 19, 2003
Posts: 17
Hi everybody. I have an EJB which is a more specialized EJB from the one that I already have. I was thinking of extending it from the more general one...but are there any issues of doing this? Like, if I have a remote client and its making calls on the more specialized Ejb bean, will this create two beans..one is the specialized and the other the general EJB? I know in Java, when you have a super class and a subclass....instantiating the subclass would initialize variables in the super class. In EJB, would this create the superclass EJB?

Thanks.
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
It will work just like "normal" Java. When the app server needs an instance of your bean it will create an instance using the ejb-class you specify in your ejb-jar.xml. You just have to make sure that the ENTIRE class follows the rules and everything should be fine. For example, if your super class has an ejbCreate(String str), and in your subclass you wanted to put a ejbCreate(String str1, String str2), then your home interface better have two create methods.
allison craig
Greenhorn

Joined: Dec 19, 2003
Posts: 17
Thank you for your reply.

What if my 'super' ejb class (Parent ejb i'm extending from) is remote? Is this a bad idea?
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
It shouldn't make any difference
allison craig
Greenhorn

Joined: Dec 19, 2003
Posts: 17
So what you're saying is that I can have local ejb which extends a remote ejb? Is this right?

I just tried it...and I'm getting errors in the generated stubs. My bean extends the remote parent bean and my local interface also extends from remote interface. Am I doing something wrong? I'm using WASD 5.1.1. In the EJB creation wizard, it doesnt provide me the option to extend from a remote ejb. The only options are the other local ejbs i currently have. So what I did instead is manually code it in.

I'm thinking to myself, can a local ejb really extend from a remote ejb?


Thanks.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by allison craig:
So what you're saying is that I can have local ejb which extends a remote ejb?

No, but keep in mind that the bean itself is neither remote nor local -- it's the interface you use to access it that determines the behavior. It's the interface that throws java.rmi.RemoteException or not; the same bean class can be exposed both locally and remotely.

If you want to have a local interface extend another bean interface, it must be the local interface (same for homes). Now, just because you create a local interface for a bean doesn't mean you have to expose it through JNDI.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extending an EJB