mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-28 06:49:09 +00:00
HHH-17935 Do not use the "auto-enable" feature for the tenant ID filter
This filter already gets enabled automatically where relevant, and critically it's not relevant when using a "root" tenant identifier.
This commit is contained in:
parent
ce97a5da2c
commit
56105a8fc6
@ -59,7 +59,7 @@ public void bind(
|
||||
"",
|
||||
singletonMap( PARAMETER_NAME, tenantIdType ),
|
||||
Collections.emptyMap(),
|
||||
true
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -76,6 +76,11 @@ public String resolveCurrentTenantIdentifier() {
|
||||
public boolean validateExistingCurrentSessions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot(String tenantId) {
|
||||
return "root".equals( tenantId );
|
||||
}
|
||||
} );
|
||||
return (SessionFactoryImplementor) sessionFactoryBuilder.build();
|
||||
}
|
||||
@ -105,6 +110,47 @@ public void test(SessionFactoryScope scope) {
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoot(SessionFactoryScope scope) {
|
||||
currentTenant = "root";
|
||||
scope.inTransaction( session -> {
|
||||
assertEquals( 0, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
|
||||
currentTenant = "mine";
|
||||
Client client = new Client( "Gavin" );
|
||||
Account acc = new Account( client );
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( client );
|
||||
session.persist( acc );
|
||||
} );
|
||||
assertEquals( "mine", acc.tenantId );
|
||||
scope.inTransaction( session -> {
|
||||
assertNotNull( session.find( Account.class, acc.id ) );
|
||||
assertEquals( 1, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
|
||||
currentTenant = "root";
|
||||
// Root tenants should find entities from other tenants
|
||||
scope.inTransaction( session -> {
|
||||
assertNotNull( session.find( Account.class, acc.id ) );
|
||||
assertEquals( 1, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
|
||||
// Root tenants should find entities from their own tenant
|
||||
Client rootClient = new Client( "Sacha" );
|
||||
Account rootAcc = new Account( rootClient );
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( rootClient );
|
||||
session.persist( rootAcc );
|
||||
} );
|
||||
assertEquals( "root", rootAcc.tenantId );
|
||||
scope.inTransaction( session -> {
|
||||
assertNotNull( session.find( Account.class, rootAcc.id ) );
|
||||
assertEquals( 2, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorOnInsert(SessionFactoryScope scope) {
|
||||
currentTenant = "mine";
|
||||
|
Loading…
x
Reference in New Issue
Block a user