首页 > 系统服务 > 详细

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

时间:2014-07-11 19:44:54      阅读:400      评论:0      收藏:0      [点我收藏+]

数据库表结构

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):多对多关系配置

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!