From 4649f5fa913661c0196f06b084d25e7eb5a7ff38 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Mon, 18 Jul 2016 13:25:21 +0800 Subject: [PATCH] Fix missing currentTenantIdentifierResolver 1. Add missing sessionFactoryBuilder.applyCurrentTenantIdentifierResolver() . 2. Use getter instead of field for consistency . (cherry picked from commit 5ea8997ca72a356791d37c982c5930d2547cb8ff) --- .../java/org/hibernate/cfg/Configuration.java | 11 ++-- .../TenantResolverConfigurationTest.java | 51 +++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index 4980a4cf78..abb02fe0c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -698,11 +698,14 @@ public class Configuration { if ( getSessionFactoryObserver() != null ) { sessionFactoryBuilder.addSessionFactoryObservers( getSessionFactoryObserver() ); } - if ( entityNotFoundDelegate != null ) { - sessionFactoryBuilder.applyEntityNotFoundDelegate( entityNotFoundDelegate ); + if ( getEntityNotFoundDelegate() != null ) { + sessionFactoryBuilder.applyEntityNotFoundDelegate( getEntityNotFoundDelegate() ); } - if ( entityTuplizerFactory != null ) { - sessionFactoryBuilder.applyEntityTuplizerFactory( entityTuplizerFactory ); + if ( getEntityTuplizerFactory() != null ) { + sessionFactoryBuilder.applyEntityTuplizerFactory( getEntityTuplizerFactory() ); + } + if ( getCurrentTenantIdentifierResolver() != null ) { + sessionFactoryBuilder.applyCurrentTenantIdentifierResolver( getCurrentTenantIdentifierResolver() ); } return sessionFactoryBuilder.build(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java new file mode 100644 index 0000000000..e8423e6a4a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java @@ -0,0 +1,51 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.multitenancy.schema; + +import org.hibernate.cfg.Configuration; +import org.hibernate.context.spi.CurrentTenantIdentifierResolver; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertSame; + +/** + * @author Vlad Mihalcea + */ +@TestForIssue(jiraKey = "HHH-10964") +public class TenantResolverConfigurationTest extends BaseCoreFunctionalTestCase { + + private TestCurrentTenantIdentifierResolver currentTenantResolver = new TestCurrentTenantIdentifierResolver(); + + @Override + protected Configuration constructAndConfigureConfiguration() { + Configuration configuration = super.constructAndConfigureConfiguration(); + configuration.setCurrentTenantIdentifierResolver( currentTenantResolver ); + return configuration; + } + + @Test + public void testConfiguration() throws Exception { + assertSame(currentTenantResolver, sessionFactory().getCurrentTenantIdentifierResolver()); + } + + private static class TestCurrentTenantIdentifierResolver implements CurrentTenantIdentifierResolver { + private String currentTenantIdentifier; + + @Override + public boolean validateExistingCurrentSessions() { + return false; + } + + @Override + public String resolveCurrentTenantIdentifier() { + return currentTenantIdentifier; + } + } +}