Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending an EJB

 
allison craig
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It shouldn't make any difference
 
allison craig
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic