【发布时间】:2016-02-22 09:41:11
【问题描述】:
我有如下表person 和personDoc:
person :
personNo
dateofBirth
firstname
LastName
MiddleName
salutationCode
personDoc :
personNo
doctype
documentNo
我必须搜索姓名 = "John" and (doctype = "passport" and documentNo = "XXXX') and (doctype = "Driving license" and documentNo = "YYYY")的人
我正在使用条件 API 进行搜索。
我已经使用别名加入了person 和persondoc 表。
如何多次添加限制(针对同一个表和列)?
注意:对于更多场景,我需要搜索:
名字如“John”和(doctype = "passport" and documentNo = "XXXX') 或 (doctype = "Driving license" and documentNo = "YYYY")的人。
【问题讨论】:
-
@DieterMeemken Criteria c = getSession().createCriteria(PersonWrapper.class,"rel");标准 firstName = Restrictions.eq("rel.firstName",fName); c.add(名字); for(PersonDocWraper pDocWrapper :argperSonWrapper.getRelationshipDocumentWrappers().values()) { aliasName = "pDOC"+pDocWrapper .getDocumentTypeCode(); c.createAlias("pDocWrapper ", aliasName, JoinType.INNER_JOIN); c.add(Restrictions.eq(aliasName.concat(".documentTypeCode"), pDocWrapper.getDocumentTypeCode())); c.add(Restrictions.eq(aliasName.concat(".documentTypeValue"), pDocWrapper.getDocumentValue())); } returnList = c.list();
标签: java hibernate hibernate-criteria