我正在进行LEFT OUTER JOIN,但我只能在第一个表上应用Restrictions.有没有办法在第二张桌子上申请?
这是我的代码:
Criteria criteria = this.crudService
.initializeCriteria(Applicant.class).setFetchMode("products",
FetchMode.JOIN);.
Run Code Online (Sandbox Code Playgroud)
这工作(申请人有applicantName属性):
criteria.add(Restrictions.eq("applicantName", "Markos")
Run Code Online (Sandbox Code Playgroud)
这些都不起作用(产品具有productName属性)
criteria.add(Restrictions.eq("productName", "product1")
Run Code Online (Sandbox Code Playgroud)
criteria.add(Restrictions.eq("products.productName","product1")// products:属性的名称criteria.add(Restrictions.eq("Product.productName","product1")//产品:数据库表的名称
这是我收到的例外(如果我理解正确),申请人中不存在productName属性:
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
Run Code Online (Sandbox Code Playgroud)
我尝试使用别名,但这会生成一个INNER JOIN,而不是我想要的LEFT OUTER JOIN.
如何对两个表格施加限制?
更新:
问题可能与此相同:https: //forum.hibernate.org/viewtopic.php?p = 2393694