2

Is it possible to reuse one entity class for inserting data into two tables which are identical?

I have master tables (one parent and 9 child tables) and staging tables (one parent and 9 child tables). Only table names are different and rest all same.

My use case is if there is no workflow process, data gets saved to master tables (10). If there is workflow involved, data has to be saved to staging tables and after workflow approval, it has to be copied to master tables.

Please let me know the right approach to design the entity classes and reuse the entity classes.

  • How do you want to tell JPA which table to use if not by using the class holding the data? You can absolutely do this, but would require a different persistence unit, so that one persistence unit maps the entity to one table, the other a different table. Otherwise, I don't know how - and wouldn't try it. – Chris Mar 17 '22 at 14:59

1 Answers1

0

I got directions from the answer in below link. I can apply polymorphism to use respective implementation class and @Inheritance annotation instead of @MappedSuperclass.

@MappedSuperclass and @OneToMany