首页 > 解决方案 > 当我使用多个关系路径时,Ebean 查询运算符“Fetch”不起作用

问题描述

据我了解,当我使用fetch查询对象时,Ebean 将尝试使用连接来获取关系。

例如

Ebean.find(ProjectRequest.class)
                    .fetch("attachments")
                    .findList();

这在尝试获取一个关系时按预期工作。

但是,当我尝试处理fetch多个关系时,它不会使用连接查询任何关系,而是使用单独的查询获取所有关系。

例如

Ebean.find(ProjectRequest.class)
                    .fetch("projectConstructionCosts")
                    .fetch("attachments")
                    .fetch("projectRequestComments")
                    .fetch("additionalContacts")
                    .where()
                    .in("project_status", projectStatusValues)
                    .findList();

根据本文档页面中的代码示例,我应该能够做到这一点。 https://ebean-orm.github.io/apidoc/10/io/ebean/FetchConfig.html

标签: javaormebean

解决方案


我使用“*”作为 fetchProperties 并为我工作

Ebean.find(ProjectRequest.class)
                .fetch("projectConstructionCosts", "*")
                .fetch("attachments", "*")
                .fetch("projectRequestComments", "*")
                .fetch("additionalContacts", "*")
                .where()
                .in("project_status", projectStatusValues)
                .findList();

推荐阅读