spring data jpa 表关联设置用户表关联角色表配置

User 表:

@ManyToMany(cascade = { CascadeType.MERGE })
    @JsonIgnore
    @JoinTable(name = "UserRole", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") }, inverseJoinColumns = {
            @JoinColumn(name = "role_id", referencedColumnName = "id") })
    private Collection<Role>    roles;

 

Role表:

@ManyToMany(mappedBy = "roles")
    @Basic(fetch = FetchType.EAGER)
    private Collection<User>    users;

 

posted @ 2019-05-28 14:09  零零柒  阅读(1776)  评论(0编辑  收藏  举报