hibernate多对多的注解配置中的自动生成中间表的配置:

@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;
  /*
  * <set name="courseSet" table="test_students_course">
  *    <key column="stu_id" />
  *    <many-to-many class="Course" column="cid"/>
  * </set>
  * */
  @ManyToMany
  @JoinTable(name="test_students_course",joinColumns={@JoinColumn(name="sid")},inverseJoinColumns={@JoinColumn(name="cid")})
  private Set<Course> courseSet;

  set,get方法省略

}

@Entity
@Table(name="test_course")
public class Course {
  @Id
  @SequenceGenerator(name="seqCourse",sequenceName="seq_test_course")
  @GeneratedValue(generator="seqCourse")
  private Integer cid;
  private String cname;
  @ManyToMany(mappedBy="courseSet")
  private Set<Students> stuSet;

  set,get方法省略

}

hibernate.cfg.xml