[英]Hibernate many-to-many query
我需要使用休眠SQL進行此查詢
SELECT *
FROM objectif AS ob, objectifs_intervenants AS oi
WHERE ob.collaborateurId =2
AND ob.objectifId = oi.objectifId
AND oi.personneId =1
彈射類
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "objectifId")
private int objectifId;
@ManyToMany(mappedBy = "objectifs")
private List<Intervenant> intervenants;
@ManyToOne
@JoinColumn(name = "collaborateurId")
private Collaborateur collaborateur;
干預班
@Entity
@DiscriminatorValue("intervenant")
public class Intervenant extends Personne
{
@ManyToMany
@JoinTable(name="objectifs_intervenants", joinColumns={@JoinColumn(name = "personneId")},
inverseJoinColumns = {@JoinColumn(name = "objectifId")})
private List<Objectif> objectifs;
我會建議:
select ob from Objectif ob join Intervenant i
where ob.collaborateur.collaborateurId = :collaborateurId
and i.personneId = :personneId
這將返回Objectif
對象的列表,您可以使用getIntervenants()
獲取有關SQL查詢中存在的干預的附加信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.