29
29
import org .hibernate .boot .registry .BootstrapServiceRegistryBuilder ;
30
30
import org .hibernate .cfg .Configuration ;
31
31
import org .hibernate .context .spi .CurrentTenantIdentifierResolver ;
32
+ import org .hibernate .engine .jdbc .connections .spi .MultiTenantConnectionProvider ;
32
33
33
34
import org .springframework .beans .factory .DisposableBean ;
34
35
import org .springframework .beans .factory .FactoryBean ;
@@ -85,6 +86,8 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
85
86
86
87
private Object jtaTransactionManager ;
87
88
89
+ private MultiTenantConnectionProvider multiTenantConnectionProvider ;
90
+
88
91
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver ;
89
92
90
93
private TypeFilter [] entityTypeFilters ;
@@ -238,6 +241,15 @@ public void setJtaTransactionManager(Object jtaTransactionManager) {
238
241
this .jtaTransactionManager = jtaTransactionManager ;
239
242
}
240
243
244
+ /**
245
+ * Set a {@link MultiTenantConnectionProvider} to be passed on to the SessionFactory.
246
+ * @since 4.3
247
+ * @see LocalSessionFactoryBuilder#setMultiTenantConnectionProvider
248
+ */
249
+ public void setMultiTenantConnectionProvider (MultiTenantConnectionProvider multiTenantConnectionProvider ) {
250
+ this .multiTenantConnectionProvider = multiTenantConnectionProvider ;
251
+ }
252
+
241
253
/**
242
254
* Set a {@link CurrentTenantIdentifierResolver} to be passed on to the SessionFactory.
243
255
* @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
@@ -251,7 +263,6 @@ public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver c
251
263
* <p>Default is to search all specified packages for classes annotated with
252
264
* {@code @javax.persistence.Entity}, {@code @javax.persistence.Embeddable}
253
265
* or {@code @javax.persistence.MappedSuperclass}.
254
- * @since 4.2
255
266
* @see #setPackagesToScan
256
267
*/
257
268
public void setEntityTypeFilters (TypeFilter ... entityTypeFilters ) {
@@ -444,6 +455,10 @@ public void afterPropertiesSet() throws IOException {
444
455
sfb .setJtaTransactionManager (this .jtaTransactionManager );
445
456
}
446
457
458
+ if (this .multiTenantConnectionProvider != null ) {
459
+ sfb .setMultiTenantConnectionProvider (this .multiTenantConnectionProvider );
460
+ }
461
+
447
462
if (this .currentTenantIdentifierResolver != null ) {
448
463
sfb .setCurrentTenantIdentifierResolver (this .currentTenantIdentifierResolver );
449
464
}
0 commit comments