use of org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMismatchColumnType.
@Test
public void testMismatchColumnType() {
MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NameColumn.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
Map<String, Object> settings = new HashMap<>();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(PropertiesHelper.map(properties()));
final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
try {
new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(IntegerNameColumn.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
if (metadata.getDatabase().getDialect().getVersion().isSameOrAfter(2)) {
// Reports "character varying" since 2.0
assertEquals("Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [character (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]", e.getMessage());
} else {
assertEquals("Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [varchar (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]", e.getMessage());
}
}
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
serviceRegistry.destroy();
connectionProvider.stop();
}
}
Aggregations