是否可以向@ManyToMany休眠额外表添加额外的字段?
我有这两个类(表)
@Entity
@Table(name = "course")
public class Course {
@Id
@Column(name = "courseid")
private String courseId;
@Column(name = "coursename")
private String courseName;
@Column(name = "vahed")
private int vahed;
@Column(name = "coursedep")
private int dep;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "student_course", joinColumns = @JoinColumn(name = "course_id"), inverseJoinColumns = @JoinColumn(name = "student_id"))
private Set<Student> student = new HashSet<Student>();
//Some setter and getter
和这个:
@Entity
@Table(name = "student")
public class Student {
@Id
@Column(name="studid")
private String stId;
@Column(nullable = false, name="studname")
private String studName;
@Column(name="stmajor")
private String stMajor;
@Column(name="stlevel", length=3)
private String stLevel;
@Column(name="stdep")
private int stdep;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "student_course"
,joinColumns = @JoinColumn(name = "student_id")
,inverseJoinColumns = @JoinColumn(name = "course_id")
)
private Set<Course> course = new HashSet<Course>();
//Some setter and getter
运行此代码后,在数据库中创建了一个额外的表(student_course),现在我想知道如何在此表中添加额外的字段,例如(成绩,日期和...(我的意思是student_course表))我看到一些解决方案,但我不喜欢它们,我也对它们有一些问题: