与hibernate合并时@OneToMany关系失败

时间:2014-01-09 09:43:26

标签: java mysql hibernate

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个对象

0 个答案:

没有答案