Java Hibernate Criteria select subclass
criteria-api, hibernate, java
Solution
The following should work:
Criteria c = session.createCriteria(Document.class, "document");
c.createAlias("document.recipients", "recipient");
c.add(Restrictions.in("recipient.class", Arrays.asList(SubClass1.class,
SubClass2.class,
SubClass3.class)));
c.add(Restrictions.eq("recipient.name", theName));
Problem
I want to use the Criteria API to select entities by taking the input from a search value. A document can have more recipients. A recipient has many subclasses ``` @Entity public class Document implements Serializable { @OneToMany(mappedBy="document") private List<Recipient> recipients = new ArrayList<Recipient>(); @Entity public class RecipientAccount extends Recipient { String name; ``` How can i select all documents which have a ReciepientAccount with a certain name? I need to do search all subclasses and connect them with an OR. Is there an elegant way? greetings m