use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class ForeignKeyNameTest method testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided.
@Test
@TestForIssue(jiraKey = "HHH-10247")
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/manytomany/UserGroup.hbm.xml").buildMetadata();
metadata.validate();
new SchemaExport().setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).create(EnumSet.of(TargetType.SCRIPT), metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat(fileContent.toLowerCase().contains("fk_user_group"), is(true));
assertThat(fileContent.toLowerCase().contains("fk_group_user"), is(true));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class JoinTableWithDefaultSchemaTest method testGetTableDataForJoinTableWithDefaultSchema.
@Test
@TestForIssue(jiraKey = "HHH-10978")
@RequiresDialect(SQLServerDialect.class)
public void testGetTableDataForJoinTableWithDefaultSchema() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CATALOG, "hibernate_orm_test").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false").build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Task.class).addAnnotatedClass(Project.class).buildMetadata();
metadata.validate();
// first create the schema...
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
try {
// validate the schema
new SchemaValidator().validate(metadata);
} finally {
// cleanup
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class LongVarcharValidationTest method testValidation.
@Test
public void testValidation() {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Translation.class).buildMetadata();
metadata.validate();
// create the schema
createSchema(metadata);
try {
doValidation(metadata);
} finally {
dropSchema(metadata);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingEntityContainsUnqualifiedEntityName.
@Test
public void testMissingEntityContainsUnqualifiedEntityName() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing table [UnqualifiedMissingEntity]", e.getMessage());
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project zhcet-web by zhcet-amu.
the class Hibernate5DDLExporter method schemaExport.
private Hibernate5DDLExporter schemaExport(String fileName, String targetDirectory) throws Exception {
if (entityPackages == null && entityPackages.length == 0) {
System.out.println("Not packages selected");
System.exit(0);
}
File exportFile = createExportFileAndMakeDirectory(fileName, targetDirectory);
PhysicalNamingStrategy physicalNamingStrategy;
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, dialect).applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy").build();
MetadataImplementor metadata = (MetadataImplementor) mapAnnotatedClasses(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.setOutputFile(exportFile.getAbsolutePath());
schemaExport.setDelimiter(";");
schemaExport.setFormat(true);
schemaExport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, serviceRegistry);
((StandardServiceRegistryImpl) serviceRegistry).destroy();
System.out.println(exportFile.getAbsolutePath());
return this;
}
Aggregations