繁体   English   中英

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

[英]'Many To One' attribute type should not be a container

我有这个 class:

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 

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

@ManyToOne
Somthing somthing; // but not list

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

所以如果你有

@ManyToOne
private List<Something> list;

那应该是

@OneToMany
private List<Something> list;

1- @ManyToOne 在 Hall classe 中注释一个字段,就像这样:

@ManyToOne
private Cinema cinema;

2- @OneToMany 在 Cinema classe 中注释一个集合,就像那样:

@OneToMany(mappedBy ="cinema")
private Collection<Hall> halls;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private List<Address> address;

既然是一对多的关系,那你一定是,对方是某物的列表,即List something

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM