[英]OR clause in LEFT_JOIN in hibernate criteria
How can provide OR clause in LEFT_JOIN in hibernate criteria. 如何在休眠条件的LEFT_JOIN中提供OR子句。
Criteria mainCrit=hibernateSession.createCriteria("Main.class");
Criteria aPropertyCrit=mainCrit.createCrieria("child",CriteriaSpecification.LEFT_JOIN);
It generates sql as 它生成sql为
select this_.Id,this_childId....
from main as this_
left join child as child1_ on child1_ .id=this_.childId
where.....
And I need to generate the sql as 我需要生成sql作为
select this_.Id,this_childId....
from main as this_
left join child as child1_ on child1_.id=this_.childId or child_.ParentId=this_.childId
where.....
How do I provide OR clause in LEFT_JOIN in above criteria. 如何在上述条件的LEFT_JOIN中提供OR子句。
The extending of the JOIN ... ON part, could be done, even with Criteria API. 即使使用Criteria API,也可以扩展JOIN ... ON部分。 But only to be more restrictive, ie adding the AND part.
但这只是为了进行更严格的限制,即添加AND部分。
Take a look on the overloads of the createCriteria
method, mostly the last parameter withClause : 看一下
createCriteria
方法的重载,主要是Clause的最后一个参数:
Criteria createCriteria(String associationPath,
String alias,
JoinType joinType,
Criterion withClause)
throws HibernateException
Create a new Criteria, "rooted" at the associated entity, assigning the given alias and using the specified join type. 创建一个新标准,在关联实体处“植根”,分配给定别名并使用指定的联接类型。
Parameters: 参数:
In fact, any other approach (eg adding the OR) , is breaking the mapping principal, introducing the ability to have the cross join at the end. 实际上,任何其他方法(例如,添加OR)都破坏了映射主体,从而引入了在末端进行交叉联接的能力。 see Hibernate criteria: Joining table without a mapped association
请参阅休眠条件:没有映射关联的联接表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.