日期:2014-05-20 浏览次数:20754 次
public class TTeacher {
@Id @GeneratedValue
private Integer id;
@Column(length=10,nullable=false)
private String name;
@ManyToMany(cascade={CascadeType.REFRESH},mappedBy="Ts")
private Set<SStudent> Ss=new HashSet<SStudent>();
public TTeacher() {
super();
}
public TTeacher(String name) {
super();
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Set<SStudent> getSs() {
return Ss;
}
public void setSs(Set<SStudent> ss) {
Ss = ss;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
public class SStudent {
@Id @GeneratedValue
private Integer id;
@Column(length=10,nullable=false)
private String name;
//inverseJoinColumns被维护段外键
@ManyToMany(cascade={CascadeType.REFRESH})@JoinTable(name="teacher_student",inverseJoinColumns
=@JoinColumn(name="teacher_id"),joinColumns=@JoinColumn(name="student_id"))
private Set<TTeacher> Ts=new HashSet<TTeacher>();
public SStudent() {
super();
}
public SStudent(String name) {
super();
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<TTeacher> getTs() {
return Ts;
}
public void setTs(Set<TTeacher> ts) {
Ts = ts;
}
public void addTeacher(TTeacher t){
this.Ts.add(t);
}
public void removeTeacher(TTeacher t){
if(this.Ts.contains(t))
this.Ts.remove(t);
}
@Override
public int hashCode() {
final int prime = 31;