当前位置: 首页 > 知识库问答 >
问题:

“非法尝试将非集合映射为@OneTomany、@ManyTomany或@CollectionOfElements”springboot

潘安平
2023-03-14

我有三个名称为depense、benifice和categories的实体,当我想在category实体中获取beneice_c和Depenese_C时。我会看到这个错误

“Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements” SpringBoot

依赖实体

> @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实体

> 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>公共类Categories实现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;
    
    

    

共有1个答案

彭衡
2023-03-14

Yoru@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;
 类似资料: