Search in sources :

Example 11 with DdlTransactionIsolatorTestingImpl

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();
    }
}
Also used : JdbcConnectionAccessImpl(org.hibernate.testing.boot.JdbcConnectionAccessImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) DdlTransactionIsolatorTestingImpl(org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Test(org.junit.Test)

Aggregations

DdlTransactionIsolatorTestingImpl (org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl)11 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)10 MetadataSources (org.hibernate.boot.MetadataSources)9 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)9 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)9 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)8 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)6 HashMap (java.util.HashMap)5 Metadata (org.hibernate.boot.Metadata)5 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)4 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)4 Test (org.junit.Test)4 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)3 Connection (java.sql.Connection)2 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)2 JdbcEnvironmentInitiator (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 RootClass (org.hibernate.mapping.RootClass)2