My base Entity:
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:
<?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 :
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:
<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:
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.