OneToMany relationship is not working

前端 未结 5 446
Happy的楠姐
Happy的楠姐 2020-12-24 14:35

My Tables:

Product: id, name

Offer: id, value, product_id

Entities:

@Entity
@Table(name=\"product\"         


        
5条回答
  •  孤城傲影
    2020-12-24 15:24

    I am using Eclipselink 2.5.2 version as my ORM vendor and I have faced this issue in one-to-many JPA mapping while lazy loading the containing entities. The workaround that is working for me is:-

    final List list = Collections.unmodifiableList(new ArrayList<> 
                                        (containerEntity.getContainingEntityList());
    

    The Mapping from Container Entity side is:

    @OneToMany(mappedBy = containerEntity, cascade = CascadeType.ALL, fetchType = FetchType.LAZY)
    private List containingEntityList;
    

    Mapping from Containing Entity side is:

    @ManyToOne
    @JoinColumn(name = "container_entity_id")
    private ContainerEntity containerEntity;
    

提交回复
热议问题