我在做一个LEFT OUTER JOIN,但我只能在第一个表申请的限制。有没有办法Ti对第二表格应用,以及?

下面是我的代码:

Criteria criteria = this.crudService
        .initializeCriteria(Applicant.class).setFetchMode("products",
              FetchMode.JOIN);.

此工作(申请人具有applicantName属性):

criteria.add(Restrictions.eq("applicantName", "Markos")

无论这些作品(产品具有ProductName属性)的

criteria.add(Restrictions.eq("productName", "product1")

criteria.add(Restrictions.eq( “products.productName”, “产品1”)//产品:属性的名称 criteria.add(Restrictions.eq( “Product.productName”, “产品1”)//产品:在DB表的名称

这是我收到说(如果我理解正确的话)的产品名称属性不存在申请人除外:

EJB Exception: ; nested exception is: org.hibernate.QueryException: could not resolve property: products.inventedName of: org.myCompany.applicant.entity.Applicant; nested exception is: org.hibernate.QueryException: could not resolve property: products.inventedName of: org.myCompany.applicant.entity.Applicant

我试图使用的别名,但此产生的INNER JOIN,代替LEFT OUTER JOIN我想要的。

我怎样才能在两个表适用限制?

<强>更新

问题是可能是相同的,因为这: https://forum.hibernate.org/viewtopic.php?p=2393694

有帮助吗?

解决方案

您可以指定左外的createalias加入...

.CreateAlias("products", "p", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
.Add(Restrictions.Eq("p.inventedName", inventedName));

要知道,你正在做该列有限制的左外连接......基本上使它成为一个内部联接。如果你也想不申请的产品,那么你就必须检查空产品了。

其他提示

更新

.CreateAlias("products", "p", JoinType.LEFT_OUTER_JOIN)
.Add(Restrictions.Eq("p.inventedName", inventedName));

我解决了这个问题,我创建一个新的标准,我可以在这两种情况下使用LEFT_OUTER_JOIN。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top