JPA - 更改mappedBy列

时间:2015-08-16 14:10:36

标签: java jpa hibernate-onetomany

好的,我有一个应用程序将学期映射到他们的课程;

public class Course {

    private String courseId;
    private String courseName;

    private Collection<Semester> semesters = new ArrayList<>();

    @OneToMany(targetEntity = Semester.class, mappedBy = "course")
    public Collection<Semester> getSemesters() {
        return semesters;
    }

    public void setSemesters(Collection<Semester> semesters) {
        this.semesters = semesters;
    }

    @Id
    @Column (name = "COURSE_ID")
    public String getCourseId() {
        return courseId;
    }

    public void setCourseId(String courseId) {
        this.courseId = courseId;
    }

    @Column(name = "COURSE_NAME", nullable = false, unique = true)
    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }
}

如您所见,用户类使用一对多映射映射到Semesters实体。

学期课程如下;

@Entity
@Table (name = "SEMESTERS")
public class Semester {

    private int semNum;
    private Course course;

    @ManyToOne
    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @Id
    @Column (name = "SEM_NUM")
    public int getSemNum() {
        return semNum;
    }

    public void setSemNum(int semNum) {
        this.semNum = semNum;
    }
}

如您所见,我正在使用mappedBy将课程直接映射到学期表。但问题是学期表中的字段为course_COURSE_ID

如何将此列名更改为COURSE_ID

0 个答案:

没有答案