This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Emulating entity bean inheritance

 
Akar Rafidj
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all

I'm new in this forum.
EJB specification doesn't allow EJB inheritance (promised to future spacifications), only few servers (as websphere) provide some proprietary strategies.Is there any way to emulate inheritance ? I don't need polymorphism.
A sample:
Individual customer and corporate customer implemented as entity beans, can i implement this as composie entity bean with CMP/CMR?
CustomerEJB holds common properties and IndividualCustomerEJB and CorporateCustomerEJB holding specific properties.
Other sample: Payment,credit card payment, cash payment, debit payment...
I don't want to implement each type as a separate entity bean...
Any comments?

Thanks

Akar
 
Jeremy Hsu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For ejb, you have to implement each type as a separate entity bean. There is no way around it because you can not type cast a EJB interface. Like type cast Customer to a CorporateCustomer or other way around.


About this strategy -- CustomerEJB holds common properties and IndividualCustomerEJB and CorporateCustomerEJB holding specific properties -- this is more like IndividualCustomer has relationship with Customer and etc. I will not use this approach as this is misleading to other people to interpret that way.

[ August 30, 2005: Message edited by: Jeremy Hsu ]
[ August 30, 2005: Message edited by: Jeremy Hsu ]
 
Akar Rafidj
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy

In OO good practices, composition and delegation are a better alternative to pure inheritance. I don't have and don't need to type cast, polymorphism isn't a must, the goal is to build coherent components and don't duplicate the same datas across different types of components.
I think that a strategy based on composition is realistic.There many ways to implement this solution but i don't know if this is compatible with the "J2EE standard".
PS: In EJB 2.0 spec, servers use inheritance, how do you write your CMP entity bean class ? abstract ? They are subclassed by the container..

Thanks
Akar
 
Jeremy Hsu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Akar

First of all, you can only do the composite entity thing through BMP. CMP has strict rules to conform, so that you do not need to code as much, and such strict rules will limit your ability code the CMP to load the related entities.

Anyway, EJB is not designed to handle inheritance, and if your solutions really requires complex inheritance, I suggest you look somewhere else.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic