# Problem using Multitenancy Discriminator with Hibernate Search

**URL:** <https://discourse.hibernate.org/t/problem-using-multitenancy-discriminator-with-hibernate-search/8296>\
**Category:** Hibernate Search\
**Created:** [September 25, 2023, 12:50pm UTC](https://discourse.hibernate.org/t/problem-using-multitenancy-discriminator-with-hibernate-search/8296 "2023-09-25T12:50:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VladDrakul1986](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vladdrakul1986/32/2363_2.png) [@VladDrakul1986](https://discourse.hibernate.org/u/VladDrakul1986)\
**Post date:** [September 25, 2023, 12:50pm UTC](https://discourse.hibernate.org/t/problem-using-multitenancy-discriminator-with-hibernate-search/8296/1 "2023-09-25T12:50:28Z")

</div>

My base Entity:

```auto
public abstract class MyBaseEntity {

  @Id
  @Column(name = "pkid", columnDefinition = "BINARY(16)")
  @GeneratedValue(generator = "uuid2")
  @GenericGenerator(name = "uuid2", strategy = "uuid2")
  @KeywordField(normalizer = "lowercase")
  private UUID pkid;

  @TenantId
  private String authority;
}

```

my persistence.xml:

```auto
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="my-persistence-unit">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="jakarta.persistence.schema-generation.database.action" value="none"/>
      <property name="jakarta.persistence.provider"
        value="org.hibernate.jpa.HibernatePersistenceProvider"/>
      <property name="jakarta.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
      <property name="jakarta.persistence.jdbc.url"
        value="jdbc:mysql://myurl"/>
      <property name="jakarta.persistence.jdbc.user" value="root"/>
      <property name="jakarta.persistence.jdbc.password" value=""/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
      <property name="hibernate.tenant_identifier_resolver"
        value="MyTenantIdentifierResolver"/>
      <property name="hibernate.search.backend.analysis.configurer"
        value="class:MyLuceneAnalysisConfigurer"/>
    </properties>
  </persistence-unit>
</persistence>

```

MyTenantIdentifierResolver :

```auto
public class MyTenantIdentifierResolver implements CurrentTenantIdentifierResolver {

  private String currentTenant = "unknown";

  public void setCurrentTenant(String tenant) {
    currentTenant = tenant;
  }

  @Override
  public String resolveCurrentTenantIdentifier() {
    return currentTenant;
  }

  @Override
  public boolean validateExistingCurrentSessions() {
    return !Objects.equals(currentTenant, "unknown");
  }

  @Override
  public boolean isRoot(String tenantId) {
    return Objects.equals(currentTenant, "rootTenant");
  }
}

```

This works fine for Hibernate but when using using a Hibernate SearchSession I get following error:  
`org.hibernate.search.util.common.SearchException: HSEARCH600031: Invalid tenant identifier: 'unknown'. The tenant identifier must be null, because multi-tenancy is disabled for this backend.`

Then i tried to add so additional configurations to my persistence.xml:

```auto
      <property name="hibernate.multiTenancy" value="DISCRIMINATOR"/>
      <property name="hibernate.search.backend.multi_tenancy.strategy" value="discriminator"/>

```

With this changes my applications crashes on startup with:

```auto
Caused by: org.hibernate.search.util.common.SearchException: HSEARCH000520: Hibernate Search encountered failures during bootstrap. Failures:

    default backend: 
        failures: 
          - HSEARCH000501: Invalid value for configuration property 'hibernate.search.backend.multi_tenancy.strategy': 'discriminator'. HSEARCH600149: Invalid backend configuration: mapping requires single-tenancy but multi-tenancy strategy is set.

```

How can i configure discriminator based Multitenancy for HibernateSearch?  
Iam using Hibernate 6.0.2.Final and Hibernate Search 6.1.8.Final.

---

<div class="post-metadata">

**Author:** ![mbekhta](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbekhta/32/2044_2.png) [@mbekhta](https://discourse.hibernate.org/u/mbekhta)\
**Post date:** [September 25, 2023, 1:52pm UTC](https://discourse.hibernate.org/t/problem-using-multitenancy-discriminator-with-hibernate-search/8296/2 "2023-09-25T13:52:14Z")

</div>

Hey,  
Hibernate ORM discriminator multitenancy support in Hibernate Search is going to be added in 7.0 – [[HSEARCH-4403] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HSEARCH-4403)

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [September 25, 2023, 2:51pm UTC](https://discourse.hibernate.org/t/problem-using-multitenancy-discriminator-with-hibernate-search/8296/3 "2023-09-25T14:51:57Z")

</div>

Right, I’ll update the issue as it’s not only about outbox-polling in the end.

EDIT: This change in particular will solve a problem that exists even without outbox-polling coordination:

> <https://github.com/hibernate/hibernate-search/pull/3610/files#diff-6289d8ff6422b3063de37898ba1a68d7f892fcf0145d4edc27dd518005cabb76L76-R79>
>
> https://hibernate.atlassian.net/browse/HSEARCH-4403
> 
> Opening as a draft as thi…s won't work for now while the changes are not applied to ORM
