27
27
import org .hibernate .boot .model .naming .ImplicitNamingStrategy ;
28
28
import org .hibernate .boot .model .naming .PhysicalNamingStrategy ;
29
29
import org .hibernate .boot .registry .BootstrapServiceRegistryBuilder ;
30
+ import org .hibernate .cache .spi .RegionFactory ;
30
31
import org .hibernate .cfg .Configuration ;
31
32
import org .hibernate .context .spi .CurrentTenantIdentifierResolver ;
32
33
import org .hibernate .engine .jdbc .connections .spi .MultiTenantConnectionProvider ;
@@ -109,17 +110,20 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
109
110
@ Nullable
110
111
private Object jtaTransactionManager ;
111
112
113
+ @ Nullable
114
+ private RegionFactory cacheRegionFactory ;
115
+
112
116
@ Nullable
113
117
private MultiTenantConnectionProvider multiTenantConnectionProvider ;
114
118
115
119
@ Nullable
116
120
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver ;
117
121
118
122
@ Nullable
119
- private TypeFilter [] entityTypeFilters ;
123
+ private Properties hibernateProperties ;
120
124
121
125
@ Nullable
122
- private Properties hibernateProperties ;
126
+ private TypeFilter [] entityTypeFilters ;
123
127
124
128
@ Nullable
125
129
private Class <?>[] annotatedClasses ;
@@ -259,15 +263,15 @@ public void setEntityInterceptor(Interceptor entityInterceptor) {
259
263
}
260
264
261
265
/**
262
- * Set a Hibernate 5.0 ImplicitNamingStrategy for the SessionFactory.
266
+ * Set a Hibernate 5 {@link ImplicitNamingStrategy} for the SessionFactory.
263
267
* @see Configuration#setImplicitNamingStrategy
264
268
*/
265
269
public void setImplicitNamingStrategy (ImplicitNamingStrategy implicitNamingStrategy ) {
266
270
this .implicitNamingStrategy = implicitNamingStrategy ;
267
271
}
268
272
269
273
/**
270
- * Set a Hibernate 5.0 PhysicalNamingStrategy for the SessionFactory.
274
+ * Set a Hibernate 5 {@link PhysicalNamingStrategy} for the SessionFactory.
271
275
* @see Configuration#setPhysicalNamingStrategy
272
276
*/
273
277
public void setPhysicalNamingStrategy (PhysicalNamingStrategy physicalNamingStrategy ) {
@@ -284,6 +288,18 @@ public void setJtaTransactionManager(Object jtaTransactionManager) {
284
288
this .jtaTransactionManager = jtaTransactionManager ;
285
289
}
286
290
291
+ /**
292
+ * Set the Hibernate {@link RegionFactory} to use for the SessionFactory.
293
+ * Allows for using a Spring-managed {@code RegionFactory} instance.
294
+ * <p>Note: If this is set, the Hibernate settings should not define a
295
+ * cache provider to avoid meaningless double configuration.
296
+ * @since 5.1
297
+ * @see LocalSessionFactoryBuilder#setCacheRegionFactory
298
+ */
299
+ public void setCacheRegionFactory (RegionFactory cacheRegionFactory ) {
300
+ this .cacheRegionFactory = cacheRegionFactory ;
301
+ }
302
+
287
303
/**
288
304
* Set a {@link MultiTenantConnectionProvider} to be passed on to the SessionFactory.
289
305
* @since 4.3
@@ -301,17 +317,6 @@ public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver c
301
317
this .currentTenantIdentifierResolver = currentTenantIdentifierResolver ;
302
318
}
303
319
304
- /**
305
- * Specify custom type filters for Spring-based scanning for entity classes.
306
- * <p>Default is to search all specified packages for classes annotated with
307
- * {@code @javax.persistence.Entity}, {@code @javax.persistence.Embeddable}
308
- * or {@code @javax.persistence.MappedSuperclass}.
309
- * @see #setPackagesToScan
310
- */
311
- public void setEntityTypeFilters (TypeFilter ... entityTypeFilters ) {
312
- this .entityTypeFilters = entityTypeFilters ;
313
- }
314
-
315
320
/**
316
321
* Set Hibernate properties, such as "hibernate.dialect".
317
322
* <p>Note: Do not specify a transaction provider here when using
@@ -334,6 +339,17 @@ public Properties getHibernateProperties() {
334
339
return this .hibernateProperties ;
335
340
}
336
341
342
+ /**
343
+ * Specify custom type filters for Spring-based scanning for entity classes.
344
+ * <p>Default is to search all specified packages for classes annotated with
345
+ * {@code @javax.persistence.Entity}, {@code @javax.persistence.Embeddable}
346
+ * or {@code @javax.persistence.MappedSuperclass}.
347
+ * @see #setPackagesToScan
348
+ */
349
+ public void setEntityTypeFilters (TypeFilter ... entityTypeFilters ) {
350
+ this .entityTypeFilters = entityTypeFilters ;
351
+ }
352
+
337
353
/**
338
354
* Specify annotated entity classes to register with this Hibernate SessionFactory.
339
355
* @see Configuration#addAnnotatedClass(Class)
@@ -546,6 +562,10 @@ public void afterPropertiesSet() throws IOException {
546
562
sfb .setBeanContainer (this .beanFactory );
547
563
}
548
564
565
+ if (this .cacheRegionFactory != null ) {
566
+ sfb .setCacheRegionFactory (this .cacheRegionFactory );
567
+ }
568
+
549
569
if (this .multiTenantConnectionProvider != null ) {
550
570
sfb .setMultiTenantConnectionProvider (this .multiTenantConnectionProvider );
551
571
}
@@ -554,14 +574,14 @@ public void afterPropertiesSet() throws IOException {
554
574
sfb .setCurrentTenantIdentifierResolver (this .currentTenantIdentifierResolver );
555
575
}
556
576
557
- if (this .entityTypeFilters != null ) {
558
- sfb .setEntityTypeFilters (this .entityTypeFilters );
559
- }
560
-
561
577
if (this .hibernateProperties != null ) {
562
578
sfb .addProperties (this .hibernateProperties );
563
579
}
564
580
581
+ if (this .entityTypeFilters != null ) {
582
+ sfb .setEntityTypeFilters (this .entityTypeFilters );
583
+ }
584
+
565
585
if (this .annotatedClasses != null ) {
566
586
sfb .addAnnotatedClasses (this .annotatedClasses );
567
587
}
0 commit comments