简体   繁体   English

Grails 3 - 域中的几何类型

[英]Grails 3 - Geometry type in domain

I'm trying to add a Point to a domain object in Grails 3.3.8 (current latest release).我正在尝试向 Grails 3.3.8(当前最新版本)中的域对象添加一个 Point。 Grails 3.3.8 uses Hibernate 5.1.5, which has support for hibernate-spatial. Grails 3.3.8 使用 Hibernate 5.1.5,它支持 hibernate-spatial。

In build.gradle:在 build.gradle 中:

compile group: 'org.hibernate', name: 'hibernate-spatial', version: '5.1.5.Final'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'

In config:在配置中:

driverClassName = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
dialect = 'org.hibernate.dialect.SqlServer2008SpatialDialect'

In domain, PointTest.groovy:在域中,PointTest.groovy:

package com.test

import com.vividsolutions.jts.geom.Point
class PointTest {
    Point coords

    static constraints = {
    }

    static mapping = {
        coords sqlType: 'geometry(Point,4326)'
    }
}

From what I can tell from this post on Stack Overflow , the above should work.从我从Stack Overflow 上的这篇文章中可以看出,以上应该有效。 But when I run the Grails project, the table is not created.但是当我运行 Grails 项目时,没有创建表。 If I remove the line from mapping , the table is created, but coords is of the wrong type, varbinary(255) .如果我从mapping删除该行,则会创建表,但coords的类型错误, varbinary(255)

Java version: 8 Java版本:8

Grails version: 3.3.8 Grails 版本:3.3.8

Database version: SQL Server 2017数据库版本:SQL Server 2017

dialect = 'org.hibernate.dialect.SqlServer2008SpatialDialect'

should instead be应该是

dialect = 'org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect'

The SRID is set per object and not initialized as part of the column type. SRID 是针对每个对象设置的,而不是作为列类型的一部分进行初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM