• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about ejb inheritance

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • 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!
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • 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.
 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
kettle
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kettle,
Please change your name to comply with the JavaRanch Naming Policy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!