这是我的父母班。
class Grouping{
@Id
private Long id; // primary key
private Long groupingId; // grouping id
private String name;
private Date effectiveTillDate;
@OneToMany(cascade = CascadeType.ALL,orphanRemoval = true)
private List<Status> statusList;
}
这是孩子班
class Status{
@Id
private Long id; // student id
private String statusCode; //value = pending_approval, live, pending_closure, closed
private Date effectiveTillDate;
private Long grpId; //points to primary key of parent table
private Long grpGid; // points to groupingId column of parent table
}
这是我写的说明。
public static Specification<Grouping> hasStatus(String status) {
if (status == null) {
return null;
}
String s = status.trim();
if (s.isEmpty()) {
return null;
}
return (root, query, cb) -> {
return cb.equal(root.join("statusList").get("statusCode"), s);
}
}
此处的联接位于类的字段的基础上,与我们进行的常规联接相同。该规范为我返回了一个分组列表,其中状态作为参数传递。
现在,数据库中可以有一个具有相同groupingId的分组对象的临时副本。 可以说有一个状态代码为“实时”的分组
grouping : id=1, groupingId = 11, name=test, effectiveTillDate=31/12/2025,
status[{id=1, statusCode=live, effectiveTillDate=31/12/2025, grpId = 1, grpGid = 11}]
现在,我想关闭此分组,因此我将暂时复制该分组并将其移至“ pending_closure”状态,此状态稍后可以由管理员批准,并进入“已关闭”状态,如果拒绝状态将保持“活着”。 因此,我们的新分组对象将如下所示,
grouping : id=2, groupingId = 11, name=test, effectiveTillDate=31/12/2025,
status[{id=2, statusCode=pending_closure, effectiveTillDate=31/12/2025, grpId = 1, grpGid = 11}]
以上两个分组均指相同的groupingId,其中第一个是当前状态,而后一个是该相同分组的瞬时副本。 注意:仅当当前分组的状态为“实时”时,我们才能创建临时副本。
所以
1) I want to find all the groupings who have an associated transient copy.
- I thought of checking if there are two copies for given groupingId, then one with who does not have status "live" of them must be transient, but I don't know how to do this.
2) I want to find all groupings except transient.
- I thought of checking if there are two copies for given groupingId, then one with status "live"must be transient, and if only one copy is there then should be included in the result list.