use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class TemplateTest method buildSessionFactory.
@BeforeClass
public static void buildSessionFactory() {
Configuration cfg = new Configuration();
cfg.setProperty(AvailableSettings.DIALECT, DIALECT.getClass().getName());
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(cfg.getProperties());
SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class PersisterClassProviderTest method testPersisterClassProvider.
@Test
public void testPersisterClassProvider() throws Exception {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Gate.class);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
//no exception as the GoofyPersisterClassProvider is not set
SessionFactory sessionFactory;
try {
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
sessionFactory.close();
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).addService(PersisterClassResolver.class, new GoofyPersisterClassProvider()).build();
cfg = new Configuration();
cfg.addAnnotatedClass(Gate.class);
try {
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
sessionFactory.close();
fail("The entity persister should be overridden");
} catch (MappingException e) {
assertEquals("The entity persister should be overridden", GoofyPersisterClassProvider.NoopEntityPersister.class, ((GoofyException) e.getCause()).getValue());
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
assertFalse(SessionFactoryRegistry.INSTANCE.hasRegistrations());
cfg = new Configuration();
cfg.addAnnotatedClass(Portal.class);
cfg.addAnnotatedClass(Window.class);
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).addService(PersisterClassResolver.class, new GoofyPersisterClassProvider()).build();
try {
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
sessionFactory.close();
fail("The collection persister should be overridden but not the entity persister");
} catch (MappingException e) {
assertEquals("The collection persister should be overridden but not the entity persister", GoofyPersisterClassProvider.NoopCollectionPersister.class, ((GoofyException) e.getCause()).getValue());
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
cfg = new Configuration();
cfg.addAnnotatedClass(Tree.class);
cfg.addAnnotatedClass(Palmtree.class);
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).addService(PersisterClassResolver.class, new GoofyPersisterClassProvider()).build();
try {
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
sessionFactory.close();
fail("The entity persisters should be overridden in a class hierarchy");
} catch (MappingException e) {
assertEquals("The entity persisters should be overridden in a class hierarchy", GoofyPersisterClassProvider.NoopEntityPersister.class, ((GoofyException) e.getCause()).getValue());
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
assertFalse(SessionFactoryRegistry.INSTANCE.hasRegistrations());
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class BootstrapServiceRegistryImpl method destroy.
@Override
public void destroy() {
if (!active) {
return;
}
active = false;
destroy(classLoaderServiceBinding);
destroy(strategySelectorBinding);
destroy(integratorServiceBinding);
if (childRegistries != null) {
for (ServiceRegistry serviceRegistry : childRegistries) {
if (serviceRegistry instanceof ServiceRegistryImplementor) {
ServiceRegistryImplementor serviceRegistryImplementor = (ServiceRegistryImplementor) serviceRegistry;
serviceRegistryImplementor.destroy();
}
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class OneToOneErrorTest method testWrongOneToOne.
@Test
public void testWrongOneToOne() throws Exception {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Show.class).addAnnotatedClass(ShowDescription.class);
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
ServiceRegistry serviceRegistry = null;
SessionFactory sessionFactory = null;
try {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
Assert.fail("Wrong mappedBy does not fail property");
} catch (AnnotationException e) {
//success
} finally {
if (sessionFactory != null) {
sessionFactory.close();
}
if (serviceRegistry != null) {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaCreatorImpl method doCreation.
public void doCreation(Metadata metadata, final boolean manageNamespaces, GenerationTarget... targets) {
final ServiceRegistry serviceRegistry = ((MetadataImplementor) metadata).getMetadataBuildingOptions().getServiceRegistry();
doCreation(metadata, serviceRegistry, serviceRegistry.getService(ConfigurationService.class).getSettings(), manageNamespaces, targets);
}
Aggregations