Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Home and componen interface for multiple bean classes

 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Home and component interfaces specify the services provided by a bean. I wonder whether polymorphism can be applied to enterprise bean. Instead of writing only one bean class for a given home and component interfaces, I write two bean classes(CardBean1 and CardBean2), each of which provides different functionalities. In one <session> in the deploymen descriptor, I fill <ejb-class> with CardBean1, and in another <session> I fill <ejb-class> with CardBean2.

The clien accesses the bean services via component interface. Since both beans have the same component interface, the client (a developer) does not know which bean provides the services.
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder whether it is legal to do this. If it is, do both beans have the same home interface (It is impossible! )?
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, you will have to provide two JNDI names when deploying the beans - ejb/Card1 and ejb/Card2 - because you have two session tags in the DD.

Clients looking up ejb/Card1 will be able to consume the services of CardBean1 and those looking up ejb/Card2 will be able to consume the services of CardBean2. So the clients do know which bean they are talking to.
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is quite true if the client looks up home interface from the initial context. But what if the client does not lookup home from the initial context and obtain component interface from the home interface. The interface is passed to the client as an argument. Since both beans have the same interface, the client won't know which one is which. After the client invokes getEJBHome() method from this component interface, the Home interface is returned. The Home interface is the same for both bean!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic