[org.hibernate.mapping.Column(当局)]

时间:2015-08-05 05:56:28

标签: spring hibernate spring-security

我遵循Hibernate错误: "无法确定类型:java.util.List,在表:user,对于列:[org.hibernate.mapping.Column(authorities)]"

什么可能导致问题?

此外,是否可以在没有模型角色的情况下使用它,并设置return getAuthority role" 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;
    }
}

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您必须将属性的所有注释替换为getter方法。