我正在尝试将 Point 添加到 Grails 3.3.8(当前最新版本)中的域对象。 Grails 3.3.8 使用 Hibernate 5.1.5,它支持 hibernate-spatial。
在 build.gradle 中:
compile group: 'org.hibernate', name: 'hibernate-spatial', version: '5.1.5.Final'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
在配置中:
driverClassName = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
dialect = 'org.hibernate.dialect.SqlServer2008SpatialDialect'
在域中,PointTest.groovy:
package com.test
import com.vividsolutions.jts.geom.Point
class PointTest {
Point coords
static constraints = {
}
static mapping = {
coords sqlType: 'geometry(Point,4326)'
}
}
据我所知 this post on Stack Overflow ,以上应该有效。但是当我运行 Grails 项目时,该表没有创建。如果我从 mapping
中删除该行,则会创建表,但 coords
的类型错误,varbinary(255)
。
Java版本:8
Grails 版本:3.3.8
数据库版本:SQL Server 2017
最佳答案
dialect = 'org.hibernate.dialect.SqlServer2008SpatialDialect'
应该是
dialect = 'org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect'
SRID 是按对象设置的,而不是作为列类型的一部分进行初始化。
关于Grails 3 - 域中的几何类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53146635/