[英]Hibernate many-to-many query
I need to do this query with hibernate SQL 我需要使用休眠SQL进行此查询
SELECT *
FROM objectif AS ob, objectifs_intervenants AS oi
WHERE ob.collaborateurId =2
AND ob.objectifId = oi.objectifId
AND oi.personneId =1
Ojectif class 弹射类
@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;
Intervenant class 干预班
@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;
I would suggest: 我会建议:
select ob from Objectif ob join Intervenant i
where ob.collaborateur.collaborateurId = :collaborateurId
and i.personneId = :personneId
This will return a list of Objectif
objects and you can use getIntervenants()
to get the additional info about intervenants that you had in your SQL query. 这将返回Objectif
对象的列表,您可以使用getIntervenants()
获取有关SQL查询中存在的干预的附加信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.