具有多租户问题的 Hibernate Search 6,HSEARCH000520,HSEARCH600029

Hibernate Search 6 with multitenancy issue, HSEARCH000520, HSEARCH600029

我正在使用 Hibernate 测试 Hibernate Search 6 多租户(参考 this link)并收到错误消息“HSEARCH000520:Hibernate Search 在 bootstrap 期间遇到故障”,以及更多详细信息, “HSEARCH600029:后端配置无效:索引 'Users' 需要多租户但未设置多租户策略”。

我申请我的用户实体。这是用户实体 class.

@Indexed
public class Users implements Serializable {

    private static final long serialVersionUID = 1L;
 

    @JsonbTransient
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;
    @FullTextField(analyzer = "name", projectable = Projectable.YES)
    @Size(min = 3, max = 50)
    @Column(name = "username")
    private String username;
    @Size(max = 50)
    @Column(name = "email")
    private String email;
    
    ...
    
}

和persistance.xml

  <persistence-unit name="jakartaEEPU" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:app/jdbc/myDS</jta-data-source> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties> 
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
      ...
      <property name="hibernate.cache.use_query_cache" value="true"/>
      <property name="hibernate.cache.use_second_level_cache" value="true"/>
       
      <property name="hibernate.search.backend.directory.root" value="/home/peter/hbsearch/"/>
      <property name="hibernate.search.backend.io.commit_interval" value="500"/>
      <property name="hibernate.search.backend.directory.type" value="local-filesystem"/>
      <property name="hibernate.search.backend.analysis.configurer" value="com.hibernateLuceneSearch.AnalyzerConfigurator"/>
      <property name="javax.persistence.schema-generation.database.action" value="none"/>
      <property name="hibernate.multiTenancy" value="DATABASE"/>
      <property name="hibernate.tenant_identifier_resolver" value="com.dao.multitenancy.DatabaseTenantResolver"/>
      <property name="hibernate.multi_tenant_connection_provider" value="com.dao.multitenancy.DatabaseMultiTenantProvider"/>
    </properties>
  </persistence-unit>

这个实体有没有遗漏或不正确的地方class?

您需要在后端明确选择多租户策略。只需将此 属性 添加到您的 persistence.xml:

      <property name="hibernate.search.backend.multi_tenancy.strategy" value="discriminator"/>

https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#backend-lucene-multi-tenancy

编辑:我创建了 HSEARCH-4163 来尝试更改这个无用的错误消息。

编辑 2:在 Hibernate Search 6.1 中不再需要显式配置多租户策略;参见 https://in.relation.to/2021/09/10/hibernate-search-6-1-0-Alpha1/#other-changes