注解

(六) annotateon注解

一对多 多的一端仅仅须要正常注解就能够了。

须要在一的一端进行注解一对多的关系。

使用@OneToMany

@Entity

public class Classes {

    private int id;

    private String name;

   

    // 一对多通常使用Set来映射,Set是不可反复内容。

    // 注意使用Set这个接口,不要使用HashSet,由于hibernate有延迟载入,

    private Set<Student>students = new HashSet<Student>();

    @OneToMany//进行注解为一对多的关系

    @JoinColumn(name="classesId")//在多的一端注解一个字段(名为classessid)

    public Set<Student>getStudents() {

        return students;

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/mengfanrong/p/4681781.html