zoukankan      html  css  js  c++  java
  • [Java Spring Data] @JoinTable, @JoinColumn, joinColumns and inverseJoinColumns

    @OneToMany: One Student To Many Courses.

    @JoinTable(name = "Enrollment"): Join Enrollment table.

    joinColumns: with use "student_id" to link Student and enrollment tables.

    inverseJoinColumns: Here the source table become "Enrollment", not "Stduent" anymore. Target table become "Course" table. 

    CascadeType.ALL is that the persistence will propagate (cascade) all EntityManager operations (PERSIST, REMOVE, REFRESH, MERGE, DETACH) to the relating entities. Which means if we delete a student, will also delete the Enrollemnt data from Enrollment table.

    FetchType.EAGER: Which means when loading a student related data, it will also load course data which related to that student.

    For example;

    In Course table:

      A column "department":

    @ManyToOne
    @JoinColumn(name="course_dept_id")
    private Department department;

    In Department table:

      @OneToMany(mappedBy="department")

  • 相关阅读:
    2-jenkins持续集成体系介绍
    第六天打卡
    第五天打卡(find用法)
    第五天打卡
    第四天打卡
    第三天打卡
    第一天:定个小目标,学习REDHAT,希望能去考下RHCE
    day12
    Python3的List操作和方法
    Python3字符串的操作
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14147626.html
Copyright © 2011-2022 走看看