public class LocalSessionFactoryBuilder
extends Configuration
Configuration
class,
adding SpringSessionContext
as a default and providing convenient ways
to specify a DataSource and an application class loader.
This is designed for programmatic use, e.g. in @Bean
factory methods.
Consider using LocalSessionFactoryBean
for XML bean definition files.
LocalSessionFactoryBean
Modifier and Type | Field and Description |
---|---|
private TypeFilter |
CONVERTER_TYPE_FILTER |
private static TypeFilter[] |
DEFAULT_ENTITY_TYPE_FILTERS |
private TypeFilter[] |
entityTypeFilters |
private static java.lang.String |
PACKAGE_INFO_SUFFIX |
private static java.lang.String |
RESOURCE_PATTERN |
private ResourcePatternResolver |
resourcePatternResolver |
Constructor and Description |
---|
LocalSessionFactoryBuilder(javax.sql.DataSource dataSource)
Create a new LocalSessionFactoryBuilder for the given DataSource.
|
LocalSessionFactoryBuilder(javax.sql.DataSource dataSource,
java.lang.ClassLoader classLoader)
Create a new LocalSessionFactoryBuilder for the given DataSource.
|
LocalSessionFactoryBuilder(javax.sql.DataSource dataSource,
ResourceLoader resourceLoader)
Create a new LocalSessionFactoryBuilder for the given DataSource.
|
Modifier and Type | Method and Description |
---|---|
LocalSessionFactoryBuilder |
addAnnotatedClasses(java.lang.Class<?>... annotatedClasses)
Add the given annotated classes in a batch.
|
LocalSessionFactoryBuilder |
addPackages(java.lang.String... annotatedPackages)
Add the given annotated packages in a batch.
|
private boolean |
matchesEntityTypeFilter(MetadataReader reader,
MetadataReaderFactory readerFactory)
Check whether any of the configured entity type filters matches
the current class descriptor contained in the metadata reader.
|
LocalSessionFactoryBuilder |
scanPackages(java.lang.String... packagesToScan)
Perform Spring-based scanning for entity classes, registering them
as annotated classes with this
Configuration . |
LocalSessionFactoryBuilder |
setEntityTypeFilters(TypeFilter... entityTypeFilters)
Specify custom type filters for Spring-based scanning for entity classes.
|
LocalSessionFactoryBuilder |
setJtaTransactionManager(java.lang.Object jtaTransactionManager)
Set the Spring
JtaTransactionManager or the JTA TransactionManager
to be used with Hibernate, if any. |
private static final java.lang.String RESOURCE_PATTERN
private static final java.lang.String PACKAGE_INFO_SUFFIX
private static final TypeFilter[] DEFAULT_ENTITY_TYPE_FILTERS
private final TypeFilter CONVERTER_TYPE_FILTER
private final ResourcePatternResolver resourcePatternResolver
private TypeFilter[] entityTypeFilters
public LocalSessionFactoryBuilder(javax.sql.DataSource dataSource)
dataSource
- the JDBC DataSource that the resulting Hibernate SessionFactory should be using
(may be null
)public LocalSessionFactoryBuilder(javax.sql.DataSource dataSource, java.lang.ClassLoader classLoader)
dataSource
- the JDBC DataSource that the resulting Hibernate SessionFactory should be using
(may be null
)classLoader
- the ClassLoader to load application classes frompublic LocalSessionFactoryBuilder(javax.sql.DataSource dataSource, ResourceLoader resourceLoader)
dataSource
- the JDBC DataSource that the resulting Hibernate SessionFactory should be using
(may be null
)resourceLoader
- the ResourceLoader to load application classes frompublic LocalSessionFactoryBuilder setJtaTransactionManager(java.lang.Object jtaTransactionManager)
JtaTransactionManager
or the JTA TransactionManager
to be used with Hibernate, if any. Allows for using a Spring-managed transaction
manager for Hibernate 5's session and cache synchronization, with the
"hibernate.transaction.jta.platform" automatically set to it.
A passed-in Spring JtaTransactionManager
needs to contain a JTA
TransactionManager
reference to be usable here, except for the WebSphere
case where we'll automatically set WebSphereExtendedJtaPlatform
accordingly.
Note: If this is set, the Hibernate settings should not contain a JTA platform setting to avoid meaningless double configuration.
public LocalSessionFactoryBuilder setEntityTypeFilters(TypeFilter... entityTypeFilters)
Default is to search all specified packages for classes annotated with
@javax.persistence.Entity
, @javax.persistence.Embeddable
or @javax.persistence.MappedSuperclass
.
scanPackages(java.lang.String...)
public LocalSessionFactoryBuilder addAnnotatedClasses(java.lang.Class<?>... annotatedClasses)
#addAnnotatedClass
,
scanPackages(java.lang.String...)
public LocalSessionFactoryBuilder addPackages(java.lang.String... annotatedPackages)
#addPackage
,
scanPackages(java.lang.String...)
public LocalSessionFactoryBuilder scanPackages(java.lang.String... packagesToScan) throws HibernateException
Configuration
.packagesToScan
- one or more Java package namesHibernateException
- if scanning fails for any reasonprivate boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws java.io.IOException
java.io.IOException