我需要帮助
我有2个课程(Bulettin
,Matier
)与关联(Bulletin_Matier
)ManytoMany
我需要列出所有具有idBulletin=X
hibernate条件或者命名查询
@Entity
@Table(name = "Bulletin")
public class Bulletin implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false)
private Integer id;
@Column(name = "etat", nullable = true)
private String etat;
@ManyToMany
@JoinTable(name="Bulletin_Matier",
joinColumns=@JoinColumn(name="Bull_ID"),
inverseJoinColumns=@JoinColumn(name="Matier_ID"))
private List<Matier> Matiers;
----------------------------------
AND
@Entity
@Table(name = "MATIER")
public class Matier implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false)
private int id;
@Column(name = "LIBELLE", nullable = true)
private String libelle;
@ManyToMany(mappedBy = "Matiers")
private List<Bulletin> Bulletins;
答案 0 :(得分:0)
此处无需使用Criteria
或命名查询。试试这个,
public List<Matier> getMatierList(Integer idBulletin){
Bulletin bulletin = (Bulletin) session.get(Bulletin.class, idBulletin);
return bulletin.getMatiers();
}