In JPA, Using only one get method, will be able to fetch data from different tables?

133 Views Asked by At

I have only one getCustomerUsingID().

Using the above method, dynamically I need to fetch data from different table.

Example : In JPA, getCustomerUsingID() fetch data from OrangeCustomerTable and also from AppleCustomerTable using the id which i send in parameter. is it possible?

Note:

  1. No DAO Class should be used.
  2. Entity class has mapping with tables.
1

There are 1 best solutions below

3
On

It's possible. You can write custom (maybe HQL) queries, write custom Spring Data JPA repositories / Projections, write Spring Data JPA Specifications or define mappings like this.