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

gpfsuwkq  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(450)

我有一门课:

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

但我有一个编译错误:

'Many To One' attribute type should not be a container
rslzwgfq

rslzwgfq1#

@ManyToOne 应该注解字段而不是集合。对于集合字段,正确的注解是 @OneToMany .
所以如果你有

@ManyToOne
private List<Something> list;

那应该是

@OneToMany
private List<Something> list;

相关问题