use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class DuplicateTest method testDuplicateEntityName.
@Test
public void testDuplicateEntityName() throws Exception {
Configuration cfg = new Configuration();
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
ServiceRegistry serviceRegistry = null;
SessionFactory sf = null;
try {
cfg.addAnnotatedClass(Flight.class);
cfg.addAnnotatedClass(org.hibernate.test.annotations.Flight.class);
cfg.addResource("org/hibernate/test/annotations/orm.xml");
cfg.addResource("org/hibernate/test/annotations/duplicatedgenerator/orm.xml");
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(cfg.getProperties());
sf = cfg.buildSessionFactory(serviceRegistry);
Assert.fail("Should not be able to map the same entity name twice");
} catch (AnnotationException ae) {
//success
} finally {
if (sf != null) {
sf.close();
}
if (serviceRegistry != null) {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class FetchProfileTest method testWrongClass.
@Test
public void testWrongClass() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer3.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 testUnsupportedFetchMode.
@Test
public void testUnsupportedFetchMode() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer4.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 NullablePrimaryKeyTest method testGeneratedSql.
@Test
@SuppressWarnings("unchecked")
public void testGeneratedSql() {
Map settings = new HashMap();
settings.putAll(Environment.getProperties());
settings.put(AvailableSettings.DIALECT, SQLServerDialect.class.getName());
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(settings);
try {
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Address.class);
ms.addAnnotatedClass(Person.class);
final Metadata metadata = ms.buildMetadata();
final List<String> commands = new SchemaCreatorImpl(serviceRegistry).generateCreationCommands(metadata, false);
for (String s : commands) {
log.debug(s);
}
String expectedMappingTableSql = "create table personAddress (address_id numeric(19,0), " + "person_id numeric(19,0) not null, primary key (person_id))";
Assert.assertEquals("Wrong SQL", expectedMappingTableSql, commands.get(2));
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class InvalidEnumeratedJavaTypeTest method testInvalidMapping.
@Test
public void testInvalidMapping() {
MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(TheEntity.class);
try {
metadataSources.buildMetadata();
fail("Was expecting failure");
} catch (AnnotationException ignore) {
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
Aggregations