• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance in Entity bean

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a query regarding the entity bean.
I am developing an application in which I am representing the "Card" as an entity bean. Since a card can be fall into different types like "Credit Card", "Debit Card" and etc..
Debit, credit or other card will have some common featutes like card expiry date, card issued by, and others.
So I will be mainitaining it in "Card" entity bean.
The features specific to individual card like Credit Card will have Credit Limit, whereas debit card won't have such feature.
So feature specific to individual card will be maintained at specfic entity bean like "DebitCard", "CreditCard"..
Whether it's right way of doing it? Whether I can able to use inheritance in entity beans? How to have the relationship with "Card" and "DebitCard", "CreditCard"?
Please throw some light on it.
 
Devaka Cooray
Marshal
Posts: 5168
485
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, you can have inheritance on entities. If you are using EJB 3.0, and if you do NOT need to map the super class (i.e. Card class) directly to the database, you could annotate the Card class as a MappedSuperClass and other sub classes (i.e. CreditCard, DebitCard can be exposed as entities to the database by using the @Entity annotation. In this case the Card class is used to provide the common information for sub classes.

And if you really need to map the super class too (i.e. Card class itself), there are some mapping strategies you can use. But I think the MappedSuperClass is what you really needed here.

Devaka.
 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your prompt reply. Unfortunately, I am using old EJB 2.1.
 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions on how to implement it in EJB2.1?
 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help to give some suggestion on it.
 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still having hope on this forum..any advice/help?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!