HQL和一对多查询

时间:2021-12-19 20:49:30

I have Hibernate domain objects that looks like this:

我有Hibernate域对象,如下所示:

   class Player {
      List<Item> inventory;
   }

   class Item {
      List<Enchantment> enchantments;
   }

   class Enchantment {
      boolean isSuperiorEnchantment;
   }

I need to construct an HQL query that returns to me a list of all players that have at least one item with an enchantment on it that has the isSuperiorEnchantment flag set. I can't for the life of me figure out a way to express this in HQL.

我需要构建一个HQL查询,该查询返回给我一个列表,其中包含至少一个带有附魔的项目的所有玩家,其中设置了isSuperiorEnchantment标志。我无法为我的生活找到一种在HQL中表达这种方式的方法。

Any ideas?

1 个解决方案

#1


Assuming the appropriate mappings on all of the above, the query you're looking for is:

假设上述所有内容都有适当的映射,那么您正在寻找的查询是:

select p
from Player as p
  left join p.inventory as i
  left join i.enchantments as e
where e.isSuperiorEnchantment = 1

#1


Assuming the appropriate mappings on all of the above, the query you're looking for is:

假设上述所有内容都有适当的映射,那么您正在寻找的查询是:

select p
from Player as p
  left join p.inventory as i
  left join i.enchantments as e
where e.isSuperiorEnchantment = 1