use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class QuotedTableNameSchemaUpdateTest method testSchemaUpdateWithQuotedTableName.
@Test
@TestForIssue(jiraKey = "HHH-10820")
@Skip(condition = Skip.OperatingSystem.Windows.class, message = "On Windows, MySQL is case insensitive!")
public void testSchemaUpdateWithQuotedTableName() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(QuotedTable.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, TargetType.SCRIPT), metadata);
final List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
assertThat("The update should recognize the existing table", sqlLines.isEmpty(), is(true));
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 QuotedTableNameWithForeignKeysSchemaUpdateTest method testUpdateExistingSchema.
@Test
public void testUpdateExistingSchema() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/UserGroup.hbm.xml").buildMetadata();
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class IdBagSequenceTest method testIdBagSequenceGeneratorIsCreated.
@Test
public void testIdBagSequenceGeneratorIsCreated() 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).addResource("org/hibernate/test/schemaupdate/idbag/Mappings.hbm.xml").buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat(fileContent.toLowerCase().contains("create sequence seq_child_id"), is(true));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class ForeignKeyNameTest method testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided.
@Test
@TestForIssue(jiraKey = "HHH-10169")
public void testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() 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).addResource("org/hibernate/test/schemaupdate/inheritance/Employee.hbm.xml").addResource("org/hibernate/test/schemaupdate/inheritance/Person.hbm.xml").addResource("org/hibernate/test/schemaupdate/inheritance/Manager.hbm.xml").addResource("org/hibernate/test/schemaupdate/inheritance/Payment.hbm.xml").buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat(fileContent.toLowerCase().contains("fk_emp_per"), is(true));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class ForeignKeyNameTest method testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided.
@Test
public void testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() 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).addResource("org/hibernate/test/schemaupdate/inheritance/Payment.hbm.xml").buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat(fileContent.toLowerCase().contains("fk_cc_pay"), is(true));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations