我有一个合作者和干预表。
协作者(Id Collab,协作名称,地址协作) 干预(id_Interv,Nom_Interv,End_date,Id_collab)("实体响应包含协作者类型对象)
@Entity
public class Collaborateur implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idcollaborateur;
private String nomCollaborateur;
...
}
和
@Entity
public class Intervention implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idInterv;
@Temporal(TemporalType.DATE)
private Date dateEndInterv;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idCollaborateur")
private Collaborateur collaborateur;
...
}
我如何选择所有合作者(列表)目前还没有任何干预措施.. 即没有干预的合作者或者他们所有干预的dateEndInterv小于datetimenow
我希望很明白,我的论文:
SELECT c
FROM Collaborateur c LEFT JOIN c.Intervention i
WHERE (i.dateFinIntervention<?1 or i.dateFinIntervention IS NULL)
我参与了春季数据
答案 0 :(得分:0)
您需要在Collaborateur和Intervention之间建立新关系,例如@OneToMany
:
@Entity
public class Collaborateur implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idcollaborateur;
private String nomCollaborateur;
@OneToMany
private Set<Intervention> interventions;
...
}
所以,你的JPQL将是:
SELECT c
FROM Collaborateur c
LEFT JOIN c.interventions i
WHERE (i.dateEndInterv < ?1 OR i.dateEndInterv IS NULL)