0

When one tries to eagerly load two bags the following exception is thrown

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

Acording to the following posts:

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

Hibernate cannot simultaneously fetch multiple bags

Hibernate doesn't allow fetching more than one bag because that would generate a Cartesian product.

And both posts recommend the use of Sets instead of non-indexed Lists (bags).

My question is:

Why try to load two bags would generate a Cartesian product and using sets would not?

rena
  • 1,223
  • 3
  • 17
  • 30

1 Answers1

0

A Cartesian product is generated in both cases — for bags and for sets. It doesn't matter what is used.

Meaning of this statement:

Hibernate doesn't allow fetching more than one bag because that would generate a Cartesian product.

Hibernate can process a result of a Cartesian product using sets and can't using bags. You can refer for an example here: Hibernate Exception - Simultaneously Fetch Multiple Bags

v.ladynev
  • 19,275
  • 8
  • 46
  • 67