说我有以下课程:
课程:
@Entity
public class Course {
private @Id @GeneratedValue Long id;
@ManyToMany
@JoinTable(
name = "course_subject",
joinColumns = @JoinColumn(name = "courseId"),
inverseJoinColumns = @JoinColumn(name = "subjectId"))
Set<Subject> subjects;
}
主题课程
@Entity
public class Subject {
private @Id @GeneratedValue Long id;
@ManyToMany(mappedBy = "subjects")
Set<Course> courses;
}
这将在数据库上创建正确的架构。但是,如果我想给生成的course_subject
表一个id
字段,然后在另一个类中引用该表怎么办?像这样:
@Entity
public class Class {
private @Id @GeneratedValue Long id;
// How to reference the generated table?
private Long courseSubjectId;
}
有什么方法可以通过JPA进行操作而无需创建额外的Java类?