Search code examples
spring-boothibernatejpaentitydao

Spring boot- dao pattern: how can we use a single dao for split table or do we need two seperate daos?


My spring-boot application uses DAO pattern to interacts with a Oracle as an application database. Database contains two same tables i.e. PROD & PROD-BAK . The columns are exactly the same. One holds latest data and another holds a backup data. We might need to list the data from either or both tables.

Considering this scenario, should we create two different entities/DAOs or should we go with single entity/DAO in this case? How single DAO will handle this senecio? Can we add a super DAO which has two child DAOs?


Solution

  • It is better to treat them as separate entities. You could put the column definitions in a shared super class.

    If you ever need to write to the tables you will need to name the entity being written to.

    If you only ever read the tables then perhaps the DB devs can provide a UNION of both tables.