Java Hibernate Criteria select subclass

前端 未结 1 732
夕颜
夕颜 2021-01-15 17:03

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



        
相关标签:
1条回答
  • 2021-01-15 17:08

    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));
    
    0 讨论(0)
提交回复
热议问题