Search in sources :

Example 36 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.

the class NonRegistryManagedDelayedCdiSupportTest method buildSessionFactory.

private SessionFactoryImplementor buildSessionFactory(SeContainer cdiContainer, NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
    BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().applyIntegrator(beanConsumingIntegrator).build();
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager()).applySetting(AvailableSettings.DELAY_CDI_ACCESS, "true").build();
    try {
        return (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(ssr);
        throw e;
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 37 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example.

@Test
public void test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example() {
    ClassLoader customClassLoader = Thread.currentThread().getContextClassLoader();
    Integrator customIntegrator = new BeanValidationIntegrator();
    // tag::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
    BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder();
    // add a custom ClassLoader
    bootstrapRegistryBuilder.applyClassLoader(customClassLoader);
    // manually add an Integrator
    bootstrapRegistryBuilder.applyIntegrator(customIntegrator);
    BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build();
// end::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) Integrator(org.hibernate.integrator.spi.Integrator) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Example 38 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2.

@Test
public void test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2() {
    // tag::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
    // An example using an explicitly built BootstrapServiceRegistry
    BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder().build();
    StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapRegistry);
// end::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Example 39 with BootstrapServiceRegistryBuilder

use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project spring-framework by spring-projects.

the class LocalSessionFactoryBean method getMetadataSources.

/**
 * Determine the Hibernate {@link MetadataSources} to use.
 * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources}
 * instance which is then going to be used for {@link SessionFactory} building.
 * @return the MetadataSources to use (never {@code null})
 * @since 4.3
 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources)
 */
public MetadataSources getMetadataSources() {
    this.metadataSourcesAccessed = true;
    if (this.metadataSources == null) {
        BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
        if (this.resourcePatternResolver != null) {
            builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
        }
        if (this.hibernateIntegrators != null) {
            for (Integrator integrator : this.hibernateIntegrators) {
                builder = builder.applyIntegrator(integrator);
            }
        }
        this.metadataSources = new MetadataSources(builder.build());
    }
    return this.metadataSources;
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Integrator(org.hibernate.integrator.spi.Integrator)

Aggregations

BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)39 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)34 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)31 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Test (org.junit.Test)21 MetadataSources (org.hibernate.boot.MetadataSources)16 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)12 SeContainer (javax.enterprise.inject.se.SeContainer)8 SeContainerInitializer (javax.enterprise.inject.se.SeContainerInitializer)6 Properties (java.util.Properties)5 Configuration (org.hibernate.cfg.Configuration)5 TheEntity (org.hibernate.test.cdi.events.TheEntity)5 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)4 Integrator (org.hibernate.integrator.spi.Integrator)4 FileInputStream (java.io.FileInputStream)3 SessionFactory (org.hibernate.SessionFactory)3 RegionFactory (org.hibernate.cache.spi.RegionFactory)3 ServiceRegistry (org.hibernate.service.ServiceRegistry)3 Map (java.util.Map)2 Session (org.hibernate.Session)2