Class StationSecondaire {
//Staff
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "station_principal_id", nullable = false)
public StationPrincipale getStationPrincipale() {
return this.stationPrincipale;
}
//Staff
}
Class StationPrincipale {
//Staff
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY, mappedBy = "stationPrincipale")
public Set<StationSecondaire> getStationSecondaires() {
return this.stationSecondaires;
}
//Staff
}
我有一个StationSecondaire
列表,我想用Hibernate保存在Mysql数据库中。
// StationPrincipale sp
for (StationSecondaire ss: ssList) {
ss.setStationPrincipale(sp);
}
ssDAO.mergeAll(ssList); //calls merge() to the list
结果是:db中的所有StationSecondaire
:确定,但我ssList.size()
也sp
(应该只有一个<} /强>)。
那么为什么我在db ??
中保存了ssList.size()
次sp
个对象