//一方
@Entity
@Table(name="test_classinfo")
public class ClassInfo {
  @Id
  @SequenceGenerator(name="seqClassInfo",sequenceName="seq_test_classinfo")
  @GeneratedValue(generator="seqClassInfo")
  private Integer cid;
  private String cname;
  @OneToMany(mappedBy="classInfo")//mappedBy:有二个作用:1.放弃创建中间表 2.放弃维护外键关系  

      // 在这里如果没有(mappedBy="classInfo"),会自动生成一个莫名其妙的表
  private Set<Students> students;

  set,get方法省略

}

 

//多方

@Entity
@Table(name="test_student")
public class Students {
  @Id
  @SequenceGenerator(name="seqStudents",sequenceName="seq_test_student")
  @GeneratedValue(generator="seqStudents")
  private Integer sid;
  private String sname;
  @ManyToOne(cascade=CascadeType.ALL)
  @JoinColumn(name="cid")
  private ClassInfo classInfo;

  set,get方法省略

}