use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class OneToOneSchemaTest method testUniqueKeyNotGeneratedViaAnnotations.
@Test
public void testUniqueKeyNotGeneratedViaAnnotations() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Parent.class).addAnnotatedClass(Child.class).buildMetadata();
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable(Identifier.toIdentifier("CHILD"));
assertFalse("UniqueKey was generated when it should not", childTable.getUniqueKeyIterator().hasNext());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SchemaUpdateSchemaNameTest method cleanup.
@After
public void cleanup() {
// Drops the table after the sql alter test.
StandardServiceRegistry ssr = null;
try {
// build simple configuration
final Configuration cfg = buildConfiguration(SimpleFirst.class);
// Build Standard Service Registry
ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
SessionFactory sf = cfg.buildSessionFactory(ssr);
try {
Session session = sf.openSession();
try {
session.getTransaction().begin();
session.createNativeQuery("DROP TABLE Simple").executeUpdate();
session.getTransaction().commit();
} catch (Throwable t) {
if (session.getTransaction().isActive()) {
session.getTransaction().rollback();
}
throw t;
} finally {
session.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SchemaUpdateSchemaNameTest method testSqlAlterWithTableSchemaName.
@Test
public void testSqlAlterWithTableSchemaName() throws Exception {
StandardServiceRegistry ssr = null;
try {
final Configuration cfg = buildConfiguration(SimpleNext.class);
ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
SessionFactory sf = cfg.buildSessionFactory(ssr);
try {
Session session = sf.openSession();
try {
session.getTransaction().begin();
session.createQuery("FROM Simple", SimpleNext.class).getResultList();
session.getTransaction().commit();
} catch (Throwable t) {
if (session.getTransaction().isActive()) {
session.getTransaction().rollback();
}
throw t;
} finally {
session.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SequenceReadingTest method testSequenceReading.
@Test
public void testSequenceReading() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, MyExtendedH2Dialect.class).build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
metadata.validate();
try {
// try to update the schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
try {
// clean up
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
} catch (Exception ignore) {
}
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SchemaUpdateSchemaNameTest method buildInitialSchema.
@Before
public void buildInitialSchema() throws Exception {
// Builds the initial table in the schema.
StandardServiceRegistry ssr = null;
try {
final Configuration cfg = buildConfiguration(SimpleFirst.class);
ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
cfg.buildSessionFactory(ssr).close();
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations