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;
}
}
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[]
}
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[]
}
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;
}
Aggregations