JavaEar 专注于收集分享传播有价值的技术资料

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

I have follow Hibernate error: "Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(authorities)]"

What can cause a problem?

Also, is it possible use it without model role, and set return getAuthority role "USER" by default?

User model:

@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;
    }
}

Role model:

@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个回答

    最佳答案
  1. I found solution myself. I set @Transient annotation to all method, which i don't want that it shouldn't be column in table.