1. 主表1:1子表 主表查询
1.1 **主表 MasterEntity
@OneToOne
@JoinColumn(name = "masterext")
MasterExtendEntity masterExtendEntity; //关联表
**子表 MasterExtendEntity
1.2 查询
Root<MasterEntity> root
Path<String> code = root.join("MasterExtendEntity").get("ExtField1")
Iterator iterator = query.codeList.iterator()
In invalue = cb.in(code);
while (iterator.hasNext()) {
invalue.value(iterator.next())
}
searchList.add(invalue)
2. 主表1:1子表 子查询
2.1
**子表:MasterExtendEntity
@OneToOne
@JoinColumn(name = "MasterEntityId", nullable = false)
MasterEntity masterEntity
**主表 MasterEntity
2.2查询
//子查询
Subquery< MasterExtendEntity> subquery = query.subquery(MasterExtendEntity)
Root< MasterExtendEntity> extEntityRoot = subquery.from(MasterExtendEntity)
subquery.select(extEntityRoot)
Predicate correlatePredicate = cb.equal(extEntityRoot.get("MasterEntity"), root)
subquery.where(
correlatePredicate,
cb.equal(extEntityRoot.get("code"), String), cb.equal(extEntityRoot.get("code"), String)
)
searchList.add(cb.exists(subquery))