mysql 8的hibernate空间方言

vwkv1x7d  于 2021-06-17  发布在  Mysql
关注(0)|答案(2)|浏览(430)

我使用springboot2.1和hibernate的最新版本。当我想将数据持久化到数据库时,出现以下错误:
数据截断:无法从发送到“几何体”字段的数据中获取几何体对象

@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Province {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long Id;

    String name;

    @Column(nullable = false, columnDefinition = "MultiPolygon")
    MultiPolygon multiPolygon;

}

我想问题出在我的方言里。

server:
port: 8080

logging:
    level:
        com.mousavi007.serverhavadan: debug
spring:
  mail:
    host: smtp.gmail.com
    port: 587
    username:********
    password:******
    properties:
      mail:
            smtp:
              auth: true
              starttls:
                enable: true
    protocol: smtp
    default-encoding: utf-8

  datasource:
    url: jdbc:mysql://localhost:3306/havadan
    username:*************
    password:*************
    platform: mysql
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.MySQL8Dialect

    database: mysql
    show-sql: true

MySQL8的hibernate上一个版本的spatial dilect是什么?

hk8txs48

hk8txs481#

请使用
org.hibernate.spatial.dialect.mysql.mysql8spatialdialect

pobjuy32

pobjuy322#

你应该使用 org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect 并使用正确的几何类型(在这种情况下 org.locationtech.jts.geom.MultiPolygon ). @Column 上面的注解 MultiPolygon 字段不是必需的。
查看更多:https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/hibernate_user_guide.html#spatial

相关问题