(懒)LEFT OUTER JOIN使用Hibernate Criteria API [英] (Lazy) LEFT OUTER JOIN using the Hibernate Criteria API
问题描述
我想使用Criteria API在两个表之间执行LEFT OUTER JOIN。我在Hibernate文档中找到的所有方法都是这种方法:
$ p $ Criteria criteria = this.crudService
.initializeCriteria(Applicant .class)
.setFetchMode(products,FetchMode.JOIN)
.createAlias(products,product);
然而,这要么执行一个内连接,要么执行一个右外连接,因为它的结果数量很多返回。
我也想让我的连接变得懒惰。我该怎么做?
干杯!
更新:使用别名会自动连接INNER JOIN。在我还没有掌握的背景故事中有一些东西。所以,今天没有别名。这给我留下了对两个表应用限制的问题,因为它们都有一个列(或属性,如果这更合适的话)' name '。
<如果您需要在产品表上留下加入,请执行以下操作:
..... createAlias(products,
product,Criteria.LEFT_JOIN);
I want to perform a LEFT OUTER JOIN between two tables using the Criteria API. All I could find in the Hibernate documentation is this method:
Criteria criteria = this.crudService
.initializeCriteria(Applicant.class)
.setFetchMode("products", FetchMode.JOIN)
.createAlias("products", "product");
However, this either performs an inner join or a right outer join, because of the number of results it returns.
I also want my join to be Lazy. How can I do this?
Cheers!
UPDATE: It seems that using aliases makes the join INNER JOIN automatically. There is something in the "background story" I have not grasped yet. So, no alias today. This leaves me with the problem of applying restrictions to the two tables, because they both have a column (or property, if this is more appropriate) 'name'.
If you need to left join on the products table just do:
.....createAlias("products", "product", Criteria.LEFT_JOIN);
这篇关于(懒)LEFT OUTER JOIN使用Hibernate Criteria API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!