Search code examples
spring-boothibernatehibernate-spatial

Wrong column type after upgrading from Hibernate Spatial 5.4.3 to 5.6.9


We're trying to upgrade Hibernate and Hibernate Spatial from version 5.4 to 5.6 (we're using MySQL 5.6) but when starting our Spring Boot application (running spring boot 2.7.0) we run into the following exception:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [my_polygon] in table [my_table]; found [geometry (Types#BINARY)], but expecting [polygon (Types#ARRAY)]
  at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateColumnType(AbstractSchemaValidator.java:167)
  at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:151)
  at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42)
  at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:97)
  at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:76)
  at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:204)
  at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:85)
  at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:335)
  at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1498)
  at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
  at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
  at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
  ... 195 common frames omitted

MyTable is defined like this:

@Entity
public class MyTable {
  
    @Type(type = "jts_geometry")
    @Column(name = "my_polygon", columnDefinition = "polygon")
    public Polygon myPolygon;

    // Other properties
}

I've tried removing the @Type annotation altogether but I still get the same error. How can I make this work?


Solution

  • I actually got it working by changing columnDefinition from polygon to geometry:

    @Entity
    public class MyTable {
      
        @Type(type = "jts_geometry")
        @Column(name = "my_polygon", columnDefinition = "geometry")
        public Polygon myPolygon;
    
        // Other properties
    }