我正在尝试Raadpleging从我的数据库中返回对象。这些对象包含 aPersoon和 a Les。我的目标是返回所有 Raadplegingen,其中 Les 的 ID 等于参数。
我不确定如何在我的查询中执行此操作。我也不太确定我的第一个 namedQuery 是否也会返回 Persoon 和 Les 属性,或者我是否需要一个连接。
正如您在下面看到的,我尝试使用这样的参数WHERE r.les = :lesId,我认为这是不正确的。
@Entity
@Access(AccessType.PROPERTY)
@Table(name = "Raadplegingen")
@NamedQueries({
@NamedQuery(name = "ClubRaadpleging.getAlleRaadplegingen",
query = "SELECT r FROM ClubRaadpleging r"),
@NamedQuery(name = "ClubRaadpleging.findByLes",
query = "SELECT r FROM ClubRaadpleging r JOIN ClubLes l ON l.id =r.les.id WHERE r.les = :lesId")
})
public class ClubRaadpleging implements Serializable {
private int id;
private ClubLes les;
private ClubPersoon persoon;
private Date datum;
public ClubRaadpleging() {
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "RaadplegingId")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "LesId")
public ClubLes getLes() {
return les;
}
public void setLes(ClubLes les) {
this.les = les;
}
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "PersoonId")
public ClubPersoon getPersoon() {
return persoon;
}
public void setPersoon(ClubPersoon persoon) {
this.persoon = persoon;
}
@Temporal(TemporalType.DATE)
public Date getDatum() {
return datum;
}
public void setDatum(Date datum) {
this.datum = datum;
}
}
慕工程0101907
相关分类