hibernate配置问题: 单向多对一,多方的外键列名,和一方的主键列名不同,
1个回答
2015-08-01
展开全部
(一共会生成三张表,两张实体表,一张关系表)
多端:(生成一张表,存在一个外键comp_id)
@Entity()
public class Flight implements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="COMP_ID")
public Company getCompany() {
return company;
}
...
}
一端:
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
public Set<Student> getStudent() {
return student;
}
public voidsetStudent(Set<Student> student) {
this.student = student;
}
多端:(生成一张表,存在一个外键comp_id)
@Entity()
public class Flight implements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="COMP_ID")
public Company getCompany() {
return company;
}
...
}
一端:
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
public Set<Student> getStudent() {
return student;
}
public voidsetStudent(Set<Student> student) {
this.student = student;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询