Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 获取类型不适用于筛选器_Hibernate_Jpa - Fatal编程技术网

Hibernate 获取类型不适用于筛选器

Hibernate 获取类型不适用于筛选器,hibernate,jpa,Hibernate,Jpa,我正在使用Hibernate和多租户。多租户通过过滤器和鉴别器列实现(请参阅) 这意味着在WHERE子句中,每个SQL查询都扩展为“…and tenant=?” 如果我加载一个实体,将对每个关系执行额外的选择。我想在一个SELECT中加载实体,而不是在n+1中加载实体。因此,我使用FetchType.eagent来建立关系。 这在没有多租户和过滤器的情况下运行良好。 一旦multitenancy筛选器处于活动状态,该选项将不起作用,实体管理器将执行n+1选择 有没有人知道这个问题,并知道如何解决

我正在使用Hibernate和多租户。多租户通过过滤器和鉴别器列实现(请参阅)

这意味着在WHERE子句中,每个SQL查询都扩展为“…and tenant=?”

如果我加载一个实体,将对每个关系执行额外的选择。我想在一个SELECT中加载实体,而不是在n+1中加载实体。因此,我使用FetchType.eagent来建立关系。 这在没有多租户和过滤器的情况下运行良好。 一旦multitenancy筛选器处于活动状态,该选项将不起作用,实体管理器将执行n+1选择

有没有人知道这个问题,并知道如何解决它? 是否有更好的多租户处理

对于这个问题,我希望避免使用EntityGraphs(出于各种原因)和HQL语句

这里有一个小例子

不带过滤器的输出为

    select
    foo0_.id as id1_1_0_,
    foo0_.tenant_id as tenant_i2_1_0_,
    bars1_.foo_id as foo_id1_2_1_,
    bar2_.id as bars_id2_2_1_,
    bar2_.id as id1_0_2_,
    bar2_.name as name2_0_2_ 
from
    foo foo0_ 
left outer join
    foo_bars bars1_ 
        on foo0_.id=bars1_.foo_id 
left outer join
    bar bar2_ 
        on bars1_.bars_id=bar2_.id 
where
    foo0_.id=?
带过滤器的输出为:

select
    foo0_.id as id1_1_,
    foo0_.tenant_id as tenant_i2_1_ 
from
    foo foo0_ 
where
    foo0_.tenant_id = ? 
    and foo0_.id=?

select
    bars0_.foo_id as foo_id3_0_0_,
    bars0_.id as id1_0_0_,
    bars0_.id as id1_0_1_,
    bars0_.foo_id as foo_id3_0_1_,
    bars0_.name as name2_0_1_ 
from
    bar bars0_ 
where
    bars0_.foo_id=?

我想在一个SELECT中加载实体,而不是在n+1中加载实体。因此,我使用FetchType.EAGER来表示关系。
-这是错误的说法。您应该在hql中使用
joinfetch
,以避免n+1查询问题。请看这里。你能添加你的代码以便其他人能够理解和/或重现你的问题吗?添加了一个示例