【问题标题】:'Many To One' attribute type should not be a container“多对一”属性类型不应是容器
【发布时间】:2021-07-13 21:40:00
【问题描述】:

我有这门课:

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 

【问题讨论】:

    标签: java spring spring-boot spring-mvc spring-security


    【解决方案1】:

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

    如果你有

    @ManyToOne
    private List<Something> list;
    

    应该是这样的

    @OneToMany
    private List<Something> list;
    

    【讨论】:

      【解决方案2】:

      正如错误所说,manyToOne 不应该是集合/列表,而应该是单个对象

      @ManyToOne
      Somthing somthing; // but not list
      

      【讨论】:

        猜你喜欢
        • 2020-07-03
        • 2013-05-06
        • 2015-11-14
        • 1970-01-01
        • 2019-11-26
        • 2014-01-30
        • 2018-06-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多