现在的位置: 首页 > 综合 > 正文

注解

2019年03月15日 ⁄ 综合 ⁄ 共 415字 ⁄ 字号 评论关闭

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

}

抱歉!评论已关闭.