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

DAO and inheritance

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Suppose that I have a class Person and a class Employee that extends Person.
Should I write 2 DAO for 2 classes or should I write only one.
Specifically, what should I do to implements these (or this) DAOs? For example, I should have 2 method update() to update Employee and Person or should I have only 1 method update()?

Thanks.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I see the database perspective, you will probably want to create normalized tables.

In this scenario, you can create two tables one employee and another person.To map it with hibernate, you can use table per class approach of inheritance mapping and have two Dao ,making sure that both of the entities could be handled independently as well.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another idea can be to extend your POJO's with generic bean like DataBean. This way, your CRUD operation would always be in your base hierarchy.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have a base DAO which implements the CRUD operations based upon a BaseEntity class which both Person and Employee would extend from.

Don't repeat the DAO
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic