我有2个实体类(A类和B类)映射到数据库表。它们是级联的,因此A类的保存对象也会反映与B类有关的表格的变化。现在我想要一个连接表,其中包含来自B类的主键和新实体Class(C类)的主键。我使用标准的hibernate @JoinTable注释。但是Join Table没有更新。我是否允许在休眠状态下这样做?
A类(实地考察)
@OneToMany(mappedBy = "fieldVisitId")
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.DELETE})
private Collection<Fieldvisitdetail> fieldvisitdetailCollection;
B类(Fieldvisitdetail)
@JoinTable(name = "fieldvisitgeo",
joinColumns = {
@JoinColumn(name = "fieldVisitDetailId", referencedColumnName = "fieldVisitDetailId")},
inverseJoinColumns = {
@JoinColumn(name = "geoId", referencedColumnName = "geoId")})
@ManyToMany(mappedBy = "fieldvisitdetailCollection", cascade = CascadeType.ALL)
private Set<Geo> geoId=new HashSet<Geo>();
C类(地理位置)
@ManyToMany(cascade = CascadeType.ALL)
private Set<Fieldvisitdetail> fieldvisitdetailCollection= new HashSet<Fieldvisitdetail>();
保存到数据库的代码
public void addFieldVisit(Fieldvisit visitReportInfo){
getSessionFactory().getCurrentSession().save(visitReportInfo);
}