Issue
i have three entites named depense ,benifice and categories , when i want to get the benefice_C and the Depenese_C in the category entity .this error displayed to me
“Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements” SpringBoot
Depens Entities
> @Entity
@Getter
@Setter
@Table(name="depense")
public class Depense {
@Id @GeneratedValue
@Column(name = "id_etab")
private Long idEtab;
@ManyToOne
@JoinColumn(name = "personnel_id")
private Personnel personnel;
@ManyToOne
@JoinColumn(name = "CATD")
private Categories categoriesD;
Benfice Entities
> public class Benifice {
@Column(name = "id_etab")
private Long idEtab;
@ManyToOne
@JoinColumn(name = "inscrit_id")
private Inscrit inscrit;
@ManyToOne
@JoinColumn(name = "be_C")
private Categories benificeC;
Categorie entite > public class Categories implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idCat;
@OneToMany(mappedBy = "categoriesD", fetch = FetchType.LAZY)
private Depense depense;
@OneToMany(mappedBy = "benificeC", fetch = FetchType.LAZY)
private Benifice benifice;
Solution
Your @OneToMany mapping is not correct.
You would need a List/Set/Collection of Objects if you map OneToMany.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idCat;
@OneToMany(mappedBy = "categoriesD", fetch = FetchType.LAZY)
private List<Depense> depense;
@OneToMany(mappedBy = "benificeC", fetch = FetchType.LAZY)
private List<Benifice> benifice;
Answered By - I_AM__PAUL
Answer Checked By - Terry (JavaFixing Volunteer)