In the JPA, how to write a query to load child class. For example, I need a query to load paymentSet which contains CashPayment if any, CheckPayment if any .
Thanks.
class SalesOrder {
Set<Payment> paymentSet;
}
class Payment {};
class CashPayment extends Payment;
class CheckPayment extends Payment;
How you solve this problem depends on how you’ve modeled your database. The wikibooks page on JPA Inheritance is pretty good for seeing what options are available. One option is to store all
Payments in the same table, but provide a@DiscriminatorValueto indicate which concrete class should be loaded. For example: