[英]'Many To One' attribute type should not be a container
I have this class:我有这个 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;
}
..
}
but I have this compilation error:但我有这个编译错误:
'Many To One' attribute type should not be a container
As Error says manyToOne should not be collection/list but should be single ojbect正如错误所说,manyToOne 不应该是集合/列表,而应该是单个对象
@ManyToOne
Somthing somthing; // but not list
@ManyToOne
should annotate a field not a collection. @ManyToOne
应该注释一个字段而不是一个集合。 For collection fields the right annotation is @OneToMany
.对于集合字段,正确的注释是@OneToMany
。
So if you have所以如果你有
@ManyToOne
private List<Something> list;
that should be那应该是
@OneToMany
private List<Something> list;
1- @ManyToOne annotate a field,like that, in Hall classe: 1- @ManyToOne 在 Hall classe 中注释一个字段,就像这样:
@ManyToOne
private Cinema cinema;
2- @OneToMany annotate a collection, like that, in Cinema classe: 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;
Since is a One-to-Many relationship, you must that, the other side is a list of something, ie List something既然是一对多的关系,那你一定是,对方是某物的列表,即List something
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.