gpt4 book ai didi

java - 当我需要使用两列时如何使用@oneToMany

转载 作者:行者123 更新时间:2023-12-01 18:25:17 25 4
gpt4 key购买 nike

当我尝试做类似的事情时,我无法成功解决这个问题:

    @OneToMany(mappedBy = "company", fetch = FetchType.EAGER)
private List<Coupon> coupons;
@OneToMany(mappedBy = "company", fetch = FetchType.EAGER)
private List<Employee> employes;

我不断收到此错误消息:

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'companyDBDAO': Unsatisfied dependency expressed through field 'getlocalSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getLocalSessionFactory' defined in config.SpringConfig: Invocation of init method failed; nested exception is org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags: [beans.Company.coupons, beans.Company.employes]

我对此很陌生,只有删除其中一个才能起作用..

最佳答案

删除 fetchType = FetchType.EAGER 并将 @LazyCollection(LazyCollectionOption.FALSE) 放置在两个集合上。

关于java - 当我需要使用两列时如何使用@oneToMany,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60238313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com