, . . , USER, UserDetails Spring Security.
, .
@Entity
class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany
private List<UserRole> roles;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return null;
}
@Override
public boolean isAccountNonExpired() {
return false;
}
@Override
public boolean isAccountNonLocked() {
return false;
}
@Override
public boolean isCredentialsNonExpired() {
return false;
}
@Override
public boolean isEnabled() {
return false;
}
If you put all annotations in the getters function, without displaying @OneToManyor @ManyToMany... it will work, but if you need to use this relationship, then Hibernate will break. I think Hibernate is already using annotation on top of the variable, so it doesn’t like annotating the top of functions for a consistent reason.
Thus, stick to what is common to the structure, you will not break your codes later.
source
share