use of org.hibernate.service.ServiceRegistry 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.service.ServiceRegistry 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);
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class DeprecationLoggingTest method basicTest.
@Test
public void basicTest() {
logInspection.registerListener(LogListenerImpl.INSTANCE);
MetadataSources metadataSources = new MetadataSources().addResource("org/hibernate/test/entitymode/dom4j/Car.hbm.xml");
try {
metadataSources.buildMetadata();
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SafeMappingTest method testDeclarativeMix.
@Test
public void testDeclarativeMix() throws Exception {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(IncorrectEntity.class);
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
ServiceRegistry serviceRegistry = null;
SessionFactory sessionFactory = null;
try {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(cfg.getProperties());
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
fail("Entity wo id should fail");
} 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 SecuredBindingTest method testConfigurationMethods.
@Test
public void testConfigurationMethods() throws Exception {
Configuration ac = new Configuration();
Properties p = new Properties();
p.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
p.put("hibernate.connection.driver_class", "org.hsqldb.jdbcDrive");
p.put("hibernate.connection.url", "jdbc:hsqldb:.");
p.put("hibernate.connection.username", "sa");
p.put("hibernate.connection.password", "");
p.put("hibernate.show_sql", "true");
ac.setProperties(p);
ac.addAnnotatedClass(Plane.class);
SessionFactory sf = null;
ServiceRegistry serviceRegistry = null;
try {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(p);
sf = ac.buildSessionFactory(serviceRegistry);
try {
sf.close();
} catch (Exception ignore) {
}
Assert.fail("Driver property overriding should work");
} catch (HibernateException he) {
//success
} finally {
if (sf != null) {
sf.close();
}
if (serviceRegistry != null) {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
}
Aggregations