[org.hibernate.mapping.Column(authorities)]

Posted

技术标签:

【中文标题】[org.hibernate.mapping.Column(authorities)]【英文标题】: 【发布时间】:2015-10-27 18:03:57 【问题描述】:

我有跟随休眠错误: “无法确定类型:java.util.List,表:用户,列:”

什么会导致问题?

另外,是否可以在没有模型角色的情况下使用它,并默认设置return getAuthority角色“USER”?

用户模型:

@Entity
@Table(name = "user")
public class User implements UserDetails 

    private int id;
    private String username;
    private String password;
    private List<Role> roles;


    @Id
    @GeneratedValue
    @Column(name = "id")
    public int getId() 
        return id;
    

    public void setId(int id) 
        this.id = id;
    

    @Basic
    @Column(name = "username")
    public String getUsername() 
        return username;
    

    public void setUsername(String username) 
        this.username = username;
    

    @Basic
    @Column(name = "password")
    public String getPassword() 
        return password;
    

    public void setPassword(String password) 
        this.password = password;
    


    @Override
    public String getUsername() 
        return this.username;
    

    @Override
    public boolean isAccountNonExpired() 
        return true;
    

    @Override
    public boolean isAccountNonLocked() 
        return true;
    

    @Override
    public boolean isCredentialsNonExpired() 
        return true;
    

    @Override
    public boolean isEnabled() 
        return true;
    


    @Override
    public List<Role> getAuthorities() 
        return this.roles;
    


    @OneToMany(mappedBy = "user")
    public List<Role> getRoles() 
        return this.roles;
    

    public void setRoles(List<Role> roles) 
        this.roles = roles;
    

榜样:

@Entity
@Table(name = "role")
public class Role implements GrantedAuthority 

    private int id;
    private User user;
    private String role;

    public Role() 
    

    public Role(String role)
        this.role = role;
    

    @Id
    @GeneratedValue
    public int getId() 
        return id;
    

    public void setId(int id) 
        this.id = id;
    

    @ManyToOne
    @JoinColumn(name="user_id")
    public User getUser() 
        return user;
    

    public void setUser(User user) 
        this.user = user;
    

    @Override
    public String getAuthority() 
        return this.role;
    

    @Basic
    @Column(name="role")
    public String getRole()
        return this.role;
    

    public void setRole(String role)
        this.role = role;
    

【问题讨论】:

【参考方案1】:

我自己找到了解决方案。我为所有方法设置了@Transient 注释,我不希望它不应该是表中的列。

【讨论】:

你能把修改后的例子贴在这里吗?【参考方案2】:

您必须替换属性的所有注释而不是 getter 方法。

【讨论】:

以上是关于[org.hibernate.mapping.Column(authorities)]的主要内容,如果未能解决你的问题,请参考以下文章