org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags

前端 未结 7 810
南笙
南笙 2020-12-04 20:07

Following is my code Here I am using multiple lists to fetch data from database. On fetching data from hql query it is showing exception.

Pojo Class

         


        
相关标签:
7条回答
  • 2020-12-04 20:56

    Changing to Set is the best solution. However, if you cannot not replace the List with Set (like in my case, there was a heavy use of JSF tags specific to Lists), and if you can use Hibernate proprietary annotations, you can specify @IndexColumn (name = "INDEX_COL"). That solution worked better for me, changing to Set would require tons of refactoring.

    So, your code would be something like this:

    @IndexColumn (name = "INDEX_COL")
    private List<BillPaidDetails> billPaidDetailses = new ArrayList<BillPaidDetails>();
    
    @IndexColumn (name = "INDEX_COL")
    private List<BillProduct> billProductList = new ArrayList<BillProduct>();
    

    As Igor suggested in the comments, you could also create proxy methods to return the lists. I haven't tried that, but would be a good alternative if you cannot use Hibernate proprietary annotations.

    0 讨论(0)
提交回复
热议问题