“多对一”属性类型不应是容器

Nuñ*_*ada 7 java spring spring-mvc spring-security spring-boot

我有这门课:

import org.springframework.security.core.userdetails.UserDetails;

@Entity
@Table(name="t_user")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class User implements Serializable, UserDetails {

@Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }
..
}
Run Code Online (Sandbox Code Playgroud)

但我有这个编译错误:

'Many To One' attribute type should not be a container 
Run Code Online (Sandbox Code Playgroud)

Pan*_*kos 14

@ManyToOne应该注释一个字段而不是一个集合。对于集合字段,正确的注释是@OneToMany

所以如果你有

@ManyToOne
private List<Something> list;
Run Code Online (Sandbox Code Playgroud)

那应该是

@OneToMany
private List<Something> list;
Run Code Online (Sandbox Code Playgroud)