• <tfoot id='kEjLq'></tfoot>

    <legend id='kEjLq'><style id='kEjLq'><dir id='kEjLq'><q id='kEjLq'></q></dir></style></legend>
    1. <small id='kEjLq'></small><noframes id='kEjLq'>

        <bdo id='kEjLq'></bdo><ul id='kEjLq'></ul>

      <i id='kEjLq'><tr id='kEjLq'><dt id='kEjLq'><q id='kEjLq'><span id='kEjLq'><b id='kEjLq'><form id='kEjLq'><ins id='kEjLq'></ins><ul id='kEjLq'></ul><sub id='kEjLq'></sub></form><legend id='kEjLq'></legend><bdo id='kEjLq'><pre id='kEjLq'><center id='kEjLq'></center></pre></bdo></b><th id='kEjLq'></th></span></q></dt></tr></i><div id='kEjLq'><tfoot id='kEjLq'></tfoot><dl id='kEjLq'><fieldset id='kEjLq'></fieldset></dl></div>

        如何在 JPQL 查询中过滤子集合?

        How to filter child collection in JPQL query?(如何在 JPQL 查询中过滤子集合?)

        <small id='hVg8x'></small><noframes id='hVg8x'>

            <tbody id='hVg8x'></tbody>
            • <bdo id='hVg8x'></bdo><ul id='hVg8x'></ul>
              <i id='hVg8x'><tr id='hVg8x'><dt id='hVg8x'><q id='hVg8x'><span id='hVg8x'><b id='hVg8x'><form id='hVg8x'><ins id='hVg8x'></ins><ul id='hVg8x'></ul><sub id='hVg8x'></sub></form><legend id='hVg8x'></legend><bdo id='hVg8x'><pre id='hVg8x'><center id='hVg8x'></center></pre></bdo></b><th id='hVg8x'></th></span></q></dt></tr></i><div id='hVg8x'><tfoot id='hVg8x'></tfoot><dl id='hVg8x'><fieldset id='hVg8x'></fieldset></dl></div>

                  <legend id='hVg8x'><style id='hVg8x'><dir id='hVg8x'><q id='hVg8x'></q></dir></style></legend>

                  <tfoot id='hVg8x'></tfoot>
                  本文介绍了如何在 JPQL 查询中过滤子集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下数据库模型:

                  Category -< ProductCategory >- Product -< Variant
                  

                  (CategoryProduct 是多对多关系,ProductVariant<是一对多关系/代码>)

                  (Category has many-to-many relationship with Product and Product has one-to-many relationship with Variant)

                  现在我需要获取所有 Category 记录,这些记录的产品具有 active 变体.我通过以下 JPQL 查询获取这些对象:

                  Now I need to get all Category records that have product with active variants. I'm getting these objects via the following JPQL query:

                  @Query("select distinct c from Category c join c.products as p join p.variants as pv where pv.active = true")
                  

                  效果很好 - 准确返回类别 - 但是每个 Category 都包含 所有 产品 - 不仅 这些具有 active 变体.

                  It works well - returns categories accurately - however every single Category contains all the products - not only these with active variants.

                  如何过滤掉在单个查询中处于非活动状态的产品(或变体)?

                  How can I filter out the products (or variants) that are inactive in a single query?

                  这里是一个包含数据库结构和示例数据的 postgres 脚本.对于给定的数据,两个类别(CAT 1CAT 2)、两个产品(PROD 1PROD 2)并且应该返回三个变体(VAR 1VAR 2VAR 3).

                  Here's a postgres script that with database struct and sample data. For given data two categories (CAT 1, CAT 2), two products (PROD 1, PROD 2) and three variants (VAR 1, VAR 2, VAR 3) should be returned.

                  推荐答案

                  我遇到了完全相同的问题,我花了一段时间才弄清楚它是如何工作的.当您在 JOIN 之后添加 FETCH 时,应过滤子列表,如下所示:

                  I had exactly the same problem and it took me a while to find out how this works. The child list should be filtered when you add FETCH after your JOIN like this:

                  SELECT DISTINCT c FROM Category c JOIN FETCH c.products as p join p.variants as pv where pv.active = true
                  

                  这篇关于如何在 JPQL 查询中过滤子集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                    1. <small id='rQOUN'></small><noframes id='rQOUN'>

                    2. <tfoot id='rQOUN'></tfoot>
                        <tbody id='rQOUN'></tbody>
                    3. <i id='rQOUN'><tr id='rQOUN'><dt id='rQOUN'><q id='rQOUN'><span id='rQOUN'><b id='rQOUN'><form id='rQOUN'><ins id='rQOUN'></ins><ul id='rQOUN'></ul><sub id='rQOUN'></sub></form><legend id='rQOUN'></legend><bdo id='rQOUN'><pre id='rQOUN'><center id='rQOUN'></center></pre></bdo></b><th id='rQOUN'></th></span></q></dt></tr></i><div id='rQOUN'><tfoot id='rQOUN'></tfoot><dl id='rQOUN'><fieldset id='rQOUN'></fieldset></dl></div>

                      <legend id='rQOUN'><style id='rQOUN'><dir id='rQOUN'><q id='rQOUN'></q></dir></style></legend>

                            <bdo id='rQOUN'></bdo><ul id='rQOUN'></ul>