use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class InheritanceSchemaUpdateTest method testBidirectionalOneToManyReferencingRootEntity.
@Test
public void testBidirectionalOneToManyReferencingRootEntity() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Step.class).addAnnotatedClass(GroupStep.class).buildMetadata();
metadata.validate();
try {
try {
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class TestFkUpdating method testUpdate.
@Test
public void testUpdate() {
System.out.println("********* Starting SchemaUpdate for TEST *************************");
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
System.out.println("********* Completed SchemaUpdate for TEST *************************");
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class CrossSchemaForeignKeyGenerationTest method testSchemaUpdateDoesNotFailResolvingCrossSchemaForeignKey.
@Test
@TestForIssue(jiraKey = "HHH-10802")
public void testSchemaUpdateDoesNotFailResolvingCrossSchemaForeignKey() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(SchemaOneEntity.class);
metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
new SchemaExport().setOutputFile(output.getAbsolutePath()).setFormat(false).create(EnumSet.of(TargetType.DATABASE), metadata);
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).execute(EnumSet.of(TargetType.DATABASE), metadata);
new SchemaExport().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).drop(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class SchemaUpdateDelimiterTest method testSchemaUpdateApplyDelimiterToGeneratedSQL.
@Test
public void testSchemaUpdateApplyDelimiterToGeneratedSQL() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").build();
try {
File output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(EXPECTED_DELIMITER).setFormat(false).execute(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
for (String line : sqlLines) {
assertThat("The expected delimiter is not applied " + line, line.endsWith(EXPECTED_DELIMITER), is(true));
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class MigrationTest method testSimpleColumnAddition.
@Test
public void testSimpleColumnAddition() {
String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";
MetadataImplementor v1metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource1).buildMetadata();
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v1metadata);
final SchemaUpdate v1schemaUpdate = new SchemaUpdate();
v1schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v1metadata);
assertEquals(0, v1schemaUpdate.getExceptions().size());
MetadataImplementor v2metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource2).buildMetadata();
final SchemaUpdate v2schemaUpdate = new SchemaUpdate();
v2schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v2metadata);
assertEquals(0, v2schemaUpdate.getExceptions().size());
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v2metadata);
}
Aggregations