休眠:为什么装载两个袋子会产生笛卡尔积? [英] Hibernate: Why load two bags would generate a cartesian product?
问题描述
当一个人试图急切地装载两个行李时,会抛出以下异常
When one tries to eagerly load two bags the following exception is thrown
org.hibernate.loader.MultipleBagFetchException:无法同时进行 取出多个袋子
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
根据以下帖子:
org.hibernate.loader.MultipleBagFetchException:无法同时提取多个包
Hibernate不允许提取多个包,因为这会生成笛卡尔积.
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).
我的问题是:
为什么尝试装载两个袋子会产生笛卡尔积,而使用套子却不会?
Why try to load two bags would generate a Cartesian product and using sets would not?
推荐答案
在两种情况下(袋和套)都会生成笛卡尔积.不管使用什么.
A Cartesian product is generated in both cases — for bags and for sets. It doesn't matter what is used.
此声明的含义:
Hibernate不允许提取多个包,因为这会生成笛卡尔积.
Hibernate doesn't allow fetching more than one bag because that would generate a Cartesian product.
Hibernate可以使用集合来处理笛卡尔积的结果,而不能使用袋子.您可以在此处参考示例: 休眠异常-同时获取多个包
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
这篇关于休眠:为什么装载两个袋子会产生笛卡尔积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!