我有這兩個類(表)可以添加額外的字段到@ManyToMany Hibernate額外的表嗎?
@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表)) 我看到一些解決方案,但我不喜歡他們,我也有一些問題,他們說:
您可以使用\ @OrderColumn添加一個額外的列,這是一個int列,用於存儲many2many關係的排序順序。我希望他們會添加一個\ @TempolalColumns來添加fromDate和toDate字段 – 2013-08-09 06:43:48