'Many To One' attribute type should not be a container
Asked Answered
H

4

8

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 
Herries answered 19/4, 2021 at 17:0 Comment(0)
S
14

@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;
Shoifet answered 19/4, 2021 at 17:5 Comment(0)
I
4

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

@ManyToOne
Somthing somthing; // but not list
Iconoscope answered 7/5, 2021 at 13:17 Comment(0)
I
0

1- @ManyToOne annotate a field,like that, in Hall classe:

@ManyToOne
private Cinema cinema;

2- @OneToMany annotate a collection, like that, in Cinema classe:

@OneToMany(mappedBy ="cinema")
private Collection<Hall> halls;
Imaginal answered 30/11, 2022 at 13:1 Comment(0)
R
0
@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, i.e List something

Rainwater answered 9/1, 2023 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.