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

Viewed 8546

I have this 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 
2 Answers

@ManyToOne should annotate a field not a collection. For collection fields the right annotation is @OneToMany.

So if you have

@ManyToOne
private List<Something> list;

that should be

@OneToMany
private List<Something> list;

As Error says manyToOne should not be collection/list but should be single ojbect

@ManyToOne
Somthing somthing; // but not list
Related