Package org.hibernate.boot

This package contains the interfaces that make up the bootstrap API for Hibernate. They collectively provide a way to specify configuration information and construct a new instance of SessionFactory.

Configuring Hibernate using these APIs usually involves working with:

  1. StandardServiceRegistryBuilder, then
  2. MetadataSources and MetadataBuilder, and
  3. finally, with 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, BootstrapServiceRegistryBuilder might also be used.

See the Native Bootstrapping guide for more details.

Included in subpackages under this namespace are: