Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Home and componen interface for multiple bean classes

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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! )?
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic