• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MultipleBagFetchException: cannot simultaneously fetch multiple bags is there a workaround

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This exception Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags is caused by an eager fetch within a fetch

I have an entity which contains the following one to many mapping



TraderPortfoilio contains a one to many mapping


A eager fetch within an eager fetch will cause the exception cannot simultaneously fetch multiple bags

But there has to be a workaround to allow multiple eager fetches to load a parent an all its child objects into the cache at one load.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Changing list to set worked, the difference between sets an lists is that sets dont allow duplicates, so i guess an eager fetch within an eager fetch can depending on how JPA or hibernate work under the covers can cause problems such as retieving duplicates on the select. So forcing you to use the set collection.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That works. Also in cases where I needed the list I have used a hibernate specific annotation on the collection (see below)


In order for this to work you will need to remove the (fetch = FetchType.EAGER).

I am not sure if they addressed this yet in hibernate 4 or not but the above works for lists in 3.x
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill will try that, just to see if the data in the lists is returned correct no duplicates or other poblems.
 
reply
    Bookmark Topic Watch Topic
  • New Topic