Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How support multiple tenant root with hibernate6 ? #35424

Closed
seepine opened this issue Aug 20, 2023 · 6 comments · Fixed by #35492
Closed

How support multiple tenant root with hibernate6 ? #35424

seepine opened this issue Aug 20, 2023 · 6 comments · Fixed by #35492
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/enhancement New feature or request
Milestone

Comments

@seepine
Copy link
Contributor

seepine commented Aug 20, 2023

Description

In Springboot

application.yml

spring:
  jpa:
    properties:
      hibernate:
        multiTenancy: true
        tenant_identifier_resolver: com.example.config.TenantResolver

TenantResolver.java

public interface CurrentTenantIdentifierResolver {
        // set tenant value
	String resolveCurrentTenantIdentifier();
   
        // true will query all tenant data
	default boolean isRoot(String tenantId) {
		return false;
	}
}

But in Quarkus 3.x

I can not find how to query ignore tenant like CurrentTenantIdentifierResolver .isRoot

application.properties

quarkus.hibernate-orm.multitenant=DISCRIMINATOR

CustomTenantResolver.java

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {

  // what is this ?
  @Override
  public String getDefaultTenantId() {
    return "0";
  }

  @Override
  public String resolveTenantId() {
    return Optional.ofNullable(TenantUtil.getTenantId()).map(Serializable::toString).orElse(null);
  }
}

Implementation ideas

like this

        // true will query all tenant data
	default boolean isRoot(String tenantId) {
		return false;
	}
@seepine seepine added the kind/enhancement New feature or request label Aug 20, 2023
@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Aug 20, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 20, 2023

/cc @Sanne (hibernate-orm), @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere
Copy link
Member

Thanks for reporting.

Note: this relates to #35332

Quoting my comment there; a PR solving this would need to:

  • add the missing method to io.quarkus.hibernate.orm.runtime.tenant.TenantResolver

  • implement isRoot() in

    public final class HibernateCurrentTenantIdentifierResolver implements CurrentTenantIdentifierResolver {

  • add a simple test (checking you have access to all tenants) in integration-tests/hibernate-orm-tenancy/discriminator/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/CustomTenantResolver.java / integration-tests/hibernate-orm-tenancy/discriminator/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/FruitResource.java / integration-tests/hibernate-orm-tenancy/discriminator/src/test/java/io/quarkus/it/hibernate/multitenancy/fruit/HibernateTenancyFunctionalityTest.java

seepine added a commit to seepine/quarkus that referenced this issue Aug 23, 2023
yrodiere pushed a commit to seepine/quarkus that referenced this issue Aug 23, 2023
seepine added a commit to seepine/quarkus that referenced this issue Aug 23, 2023
seepine added a commit to seepine/quarkus that referenced this issue Aug 23, 2023
seepine added a commit to seepine/quarkus that referenced this issue Aug 23, 2023
@quarkus-bot quarkus-bot bot added this to the 3.4 - main milestone Aug 23, 2023
@dengchaofeng
Copy link

When will this issue be merged into version 3.2. x? As far as I know, version 3.2 is the LTS version

@yrodiere
Copy link
Member

yrodiere commented Oct 9, 2023

As a rule we don't backport new features and enhancements.

That being said, @gsmet asked if someone wanted this backported, exceptionally. But he got no answer, so there are no plans to backport at the moment. I doubt he'd want to backport to 3.2 anyway, but who knows.

@dengchaofeng
Copy link

I understand that this is a bug and not a new feature.

@yrodiere
Copy link
Member

I understand that this is a bug and not a new feature.

The PR itself is called "Support for multi tenancy root mode", and it adds the ability to declare one tenant as the "root", able to access all data. Discriminator multi-tenancy can reasonably be used without it as far as I know, considering no other form of multi-tenancy supports it. Looks like a feature to me.

Anyway, we can argue about the semantics all day, but at the end you'll need someone who actually works on LTS (i.e., not me, possibly @gsmet) to agree to do the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants