Win a copy of Terraform in Action this week in the Cloud 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

question about ejb inheritance

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello
in my ejb tier,i have several session bean,all of them share several common method,such as "readEmployee().....",etc.
in not order to repeatly code them in every session bean,i want to wirte a base session bean which have remote,home and iomplementing class just same as the normal session bean,then other session beans can inherit from the base bean by all of the remote,home interface and the ejb implementation,so that the common method can be shared among multiple session bean.
is this a vaible solution? thank you!
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no "component inherritence" in EJB, so one Bean can not inherrit from another Bean.
But the interfaces and classes that you use to build those beans can use normal Java inherritence.
So you can have a base remote (or local) interface, and have your individual beans remote interfaces extend it.
And you can have some implementation in a base session bean class, and have the implementation classes for individual beans extend it and inherrit the base classes behavior for common methods.
But you can not use any inherritence for the Home interfaces. This is because the methods on Home - like create() - must return the remote interface type for the specific bean. You can't change the return type when you override a method.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I feel its better to use composition of the util object which has readEmployee() method instead of inheriting
Hari
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for all of your helps
but to babu:
could you tell me if there are any disadvantages by using inheritance in the ejb?
could you give me more detailed instruction?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use inheritance without any problem. Just extend the Parent EJB.
I have done it and works fine and dandy.
Kettle
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kettle,
Please change your name to comply with the JavaRanch Naming Policy.
reply
    Bookmark Topic Watch Topic
  • New Topic