Hibernate 反向自身多对多 (annotation)

来源:互联网 发布:mac如何加密文件夹 编辑:程序博客网 时间:2024/04/29 18:21

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    public Long getUserId() {
        return userId;
    }
    @ManyToMany(targetEntity=User.class)
    public Set<User> getFathers() {
        return fathers;
    }
    @ManyToMany(targetEntity=User.class,mappedBy="fathers")
    @Cascade(value={CascadeType.SAVE_UPDATE})
    public Set<User> getChildren() {
        return children;
    }
    
    
    
    private Long userId;
    private String username;
    private Set<User> fathers=new HashSet<User>();
    private Set<User> children=new HashSet<User>();
    
   

原创粉丝点击