Assuming the following classes and entity hierarchy:
@Entity
Class Ticket {
@ManyToOne(optional = true)
private Customer customer;
}
@Entity
Class Customer {}
@Entity
Class Person extends Customer {}
@Class CustomPerson extends Person {}
How can I request for all tickets that have customertype Person or any subclass of Person (i.e. CustomPerson)?
I can easily create a predicate by type:
Predicate p = criteriaBuilder.equal(Ticket_...type(), criteriaBuilder.literal(Person.class));
but it will filter out CustomPerson.
If there is no general way to handle this (in JPA 2.0), I could overcome this problem if I could define all entities extending Person at runtime; in this case I could use
Predicate p = criteriaBuilder.in(Ticket_...type(), listOfPersonSubclasses);
source
share