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

前端 未结 7 842
南笙
南笙 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 billPaidDetailses = new ArrayList();
    
    @IndexColumn (name = "INDEX_COL")
    private List billProductList = new ArrayList();
    

    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.

提交回复
热议问题