30
30
import org .hibernate .cfg .Configuration ;
31
31
import org .hibernate .context .spi .CurrentTenantIdentifierResolver ;
32
32
import org .hibernate .engine .jdbc .connections .spi .MultiTenantConnectionProvider ;
33
+ import org .hibernate .integrator .spi .Integrator ;
34
+ import org .hibernate .service .ServiceRegistry ;
33
35
34
36
import org .springframework .beans .factory .DisposableBean ;
35
37
import org .springframework .beans .factory .FactoryBean ;
44
46
import org .springframework .core .task .AsyncTaskExecutor ;
45
47
import org .springframework .core .type .filter .TypeFilter ;
46
48
import org .springframework .lang .Nullable ;
47
- import org .springframework .util .Assert ;
48
49
49
50
/**
50
- * {@link FactoryBean} that creates a Hibernate
51
- * {@link SessionFactory}. This is the usual way to set up a shared
52
- * Hibernate SessionFactory in a Spring application context; the SessionFactory can
53
- * then be passed to Hibernate-based data access objects via dependency injection.
51
+ * {@link FactoryBean} that creates a Hibernate {@link SessionFactory}. This is the usual
52
+ * way to set up a shared Hibernate SessionFactory in a Spring application context; the
53
+ * SessionFactory can then be passed to data access objects via dependency injection.
54
54
*
55
- * <p>Compatible with Hibernate 5.0/5.1 as well as 5.2, as of Spring 4.3 .
55
+ * <p>Compatible with Hibernate 5.0/5.1 as well as 5.2/5.3 , as of Spring 5.1 .
56
56
*
57
57
* @author Juergen Hoeller
58
58
* @since 4.2
@@ -120,6 +120,9 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
120
120
@ Nullable
121
121
private AsyncTaskExecutor bootstrapExecutor ;
122
122
123
+ @ Nullable
124
+ private Integrator [] hibernateIntegrators ;
125
+
123
126
private boolean metadataSourcesAccessed = false ;
124
127
125
128
@ Nullable
@@ -358,14 +361,28 @@ public void setBootstrapExecutor(AsyncTaskExecutor bootstrapExecutor) {
358
361
this .bootstrapExecutor = bootstrapExecutor ;
359
362
}
360
363
364
+ /**
365
+ * Specify one or more Hibernate {@link Integrator} implementations to apply.
366
+ * <p>This will only be applied for an internally built {@link MetadataSources}
367
+ * instance. {@link #setMetadataSources} effectively overrides such settings,
368
+ * with integrators to be applied to the externally built {@link MetadataSources}.
369
+ * @since 5.1
370
+ * @see #setMetadataSources
371
+ * @see BootstrapServiceRegistryBuilder#applyIntegrator
372
+ */
373
+ public void setHibernateIntegrators (Integrator ... hibernateIntegrators ) {
374
+ this .hibernateIntegrators = hibernateIntegrators ;
375
+ }
376
+
361
377
/**
362
378
* Specify a Hibernate {@link MetadataSources} service to use (e.g. reusing an
363
379
* existing one), potentially populated with a custom Hibernate bootstrap
364
380
* {@link org.hibernate.service.ServiceRegistry} as well.
365
381
* @since 4.3
382
+ * @see MetadataSources#MetadataSources(ServiceRegistry)
383
+ * @see BootstrapServiceRegistryBuilder#build()
366
384
*/
367
385
public void setMetadataSources (MetadataSources metadataSources ) {
368
- Assert .notNull (metadataSources , "MetadataSources must not be null" );
369
386
this .metadataSourcesAccessed = true ;
370
387
this .metadataSources = metadataSources ;
371
388
}
@@ -385,6 +402,11 @@ public MetadataSources getMetadataSources() {
385
402
if (this .resourcePatternResolver != null ) {
386
403
builder = builder .applyClassLoader (this .resourcePatternResolver .getClassLoader ());
387
404
}
405
+ if (this .hibernateIntegrators != null ) {
406
+ for (Integrator integrator : this .hibernateIntegrators ) {
407
+ builder = builder .applyIntegrator (integrator );
408
+ }
409
+ }
388
410
this .metadataSources = new MetadataSources (builder .build ());
389
411
}
390
412
return this .metadataSources ;
0 commit comments