use of org.hibernate.boot.registry.BootstrapServiceRegistry 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.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class DialectFactoryTest method setUp.
@Before
public void setUp() {
final BootstrapServiceRegistry bootReg = new BootstrapServiceRegistryBuilder().applyClassLoader(DialectFactoryTest.class.getClassLoader()).build();
registry = new StandardServiceRegistryBuilder(bootReg).build();
dialectFactory = new DialectFactoryImpl();
dialectFactory.injectServices((ServiceRegistryImplementor) registry);
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class ImmutableTest method testMisplacedImmutableAnnotation.
@Test
public void testMisplacedImmutableAnnotation() {
MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Foobar.class);
try {
metadataSources.buildMetadata();
fail("Expecting exception due to misplaced @Immutable annotation");
} catch (AnnotationException ignore) {
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class FetchProfileTest method testXmlOverride.
@Test
public void testXmlOverride() {
Configuration config = new Configuration();
config.addAnnotatedClass(Customer5.class);
config.addAnnotatedClass(Order.class);
config.addAnnotatedClass(Country.class);
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
config.addInputStream(is);
SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("orders-profile"));
sessionImpl.close();
// now the same with no xml
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer5.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class FetchProfileTest method testWrongAssociationName.
@Test
public void testWrongAssociationName() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer2.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
Aggregations