• 使用annotation配置hibernate(3):多对多关系配置


    数据库表结构

    Student.java

     1 @Entity
     2 @Table(name = "student")
     3 public class Student {
     4     @Id
     5     @Column(name = "id")
     6     @GenericGenerator(name = "generator",strategy = "native")
     7     @GeneratedValue(generator = "generator")
     8     private int id;
     9     
    10     @Column(name = "name")
    11     private String name;
    12     
    13     
    14     @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    15     @JoinTable(name = "student_course",
    16                joinColumns= {@JoinColumn(name = "student_id")},
    17                inverseJoinColumns = {@JoinColumn(name = "course_id")})
    18     private Set<Course> courses = new HashSet<Course>();
    19     
    20 }

    Course.java

    @Entity
    @Table(name = "course")
    public class Course {
        @Id
        @Column(name = "id")
        @GenericGenerator(name = "generator",strategy = "native")
        @GeneratedValue(generator = "generator")
        private int id;
        
        @Column(name = "coursename")
        private String courseName;
        
        @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "courses")
        private Set<Student> students = new HashSet<Student>();
        
    }
  • 相关阅读:
    了解jQuery
    了解JavaScript
    了解DOM
    了解CSS
    UICollectionViewCell点击高亮效果(附带效果GIF)
    产品迭代缓慢的原因
    了解Web的相关知识
    HTML常用标签
    HTML常用标签效果展示
    了解数据产品经理
  • 原文地址:https://www.cnblogs.com/zanglitao/p/3833568.html
Copyright © 2020-2023  润新知