org.hibernate.SessionFactory .
Configuring Hibernate using these APIs usually involves working with:
org.hibernate.boot.registry.StandardServiceRegistryBuilder ,
then
org.hibernate.boot.MetadataSources and
org.hibernate.boot.MetadataBuilder , and
org.hibernate.boot.SessionFactoryBuilder .
StandardServiceRegistry standardRegistry =
new StandardServiceRegistryBuilder()
// supply a configuration
.configure("org/hibernate/example/hibernate.cfg.xml")
// set a configuration property
.applySetting(AvailableSettings.HBM2DDL_AUTO,
SchemaAutoTooling.CREATE_DROP.externalForm())
.build();
MetadataBuilder metadataBuilder =
new MetadataSources(standardRegistry)
// supply annotated classes
.addAnnotatedClass(MyEntity.class)
.addAnnotatedClassName("org.hibernate.example.Customer")
// supply XML-based mappings
.addResource("org/hibernate/example/Order.hbm.xml")
.addResource("org/hibernate/example/Product.orm.xml")
.getMetadataBuilder();
Metadata metadata =
metadataBuilder
// set the naming strategies
.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
.applyPhysicalNamingStrategy(new CustomPhysicalNamingStrategy())
// add a TypeContributor
.applyTypes(new CustomTypeContributor())
.build();
SessionFactoryBuilder sessionFactoryBuilder =
metadata.getSessionFactoryBuilder();
SessionFactory sessionFactory =
sessionFactoryBuilder
// supply a factory-level Interceptor
.applyInterceptor(new CustomSessionFactoryInterceptor());
// add a custom observer
.addSessionFactoryObservers(new CustomSessionFactoryObserver());
// apply a CDI BeanManager (for JPA event listeners)
.applyBeanManager(getBeanManager());
.build();
In more advanced scenarios,
org.
might also be used.
See the Native Bootstrapping guide for more details.
Included in subpackages under this namespace are:
org.hibernate.service.ServiceRegistry used during
the bootstrap process,
org.hibernate.boot.MetadataBuilder
and org.hibernate.boot.Metadata , and
org.hibernate.boot.SessionFactoryBuilder ,
org.hibernate.boot.model.naming.ImplicitNamingStrategy
and org.hibernate.boot.model.naming.PhysicalNamingStrategy ,
| Modifier and Type | Interface and Description |
|---|---|
| public interface | AttributeConverterInfo
Deprecated
for removal since 6.2. no longer used
Delayed information about an AttributeConverter.
|
| public interface | BootLogging
Logging related to Hibernate bootstrapping |
| public interface | |
| public interface | MetadataBuilder
Contract for specifying various overrides to be used in metamodel building. |
| public interface | ResourceLocator
Abstraction for locating class-path resources |
| public interface | ResourceStreamLocator
Abstraction for locating class-path resources |
| public interface | SessionFactoryBuilder
The contract for building a |
| Modifier and Type | Class and Description |
|---|---|
| public class | CacheRegionDefinition
Models the definition of caching settings for a particular region. |
| public class | InvalidMappingException
Indicates a problem parsing the mapping document at a given |
| public class | MappingException
Indicates a problem parsing a mapping document. |
| public class | MappingNotFoundException
Indicates that a mapping document could not be found at a given |
| public class | MetadataSources
Entry point for working with sources of O/R mapping metadata, either in the form of annotated classes, or as XML mapping documents. |
| public class | UnsupportedOrmXsdVersionException
Specialized exception indicating that an unsupported |
| Modifier and Type | Enum and Description |
|---|---|
| public enum | SchemaAutoTooling
Defines the possible values for hibernate.hbm2ddl.auto. |
| public enum | TempTableDdlTransactionHandling
Enum describing how creation and dropping of temporary tables should be done in terms of transaction handling. |