码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2014-07-11 19:45:18      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   使用   

数据库表结构

bubuko.com,布布扣

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>();
    
}

 

使用annotation配置hibernate(3):多对多关系配置,布布扣,bubuko.com

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

标签:style   blog   http   java   color   使用   

原文地址:http://www.cnblogs.com/zanglitao/p/3833568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!