Java Hibernate Criteria选择子类 [英] Java Hibernate Criteria select subclass
本文介绍了Java Hibernate Criteria选择子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Criteria API通过从搜索值中获取输入来选择实体。文档可以包含更多收件人。收件人有许多子类
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;
如何选择具有特定名称的ReciepientAccount的所有文件?
我需要搜索所有子类并用OR连接它们。有优雅的方式吗?
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?
问候
m
推荐答案
以下应该有效:
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));
这篇关于Java Hibernate Criteria选择子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文