2

I'm trying to add a Point to a domain object in Grails 3.3.8 (current latest release). Grails 3.3.8 uses Hibernate 5.1.5, which has support for hibernate-spatial.

In 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:

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. But when I run the Grails project, the table is not created. If I remove the line from mapping, the table is created, but coords is of the wrong type, varbinary(255).

Java version: 8

Grails version: 3.3.8

Database version: SQL Server 2017

Anonymous1
  • 3,877
  • 3
  • 28
  • 42
  • "But when I run the Grails project, the table is not created. " - Which table is not created? – Jeff Scott Brown Nov 05 '18 at 01:19
  • I am not setup here to test with SQL Server right now and that may be relevant but when I test your code in a 3.3.8 app with H2 I see the following DDL being generated: `create table point_test (id bigint generated by default as identity, version bigint not null, coords geometry(Point,4326) not null, primary key (id))`. Do you see the same if you use H2? – Jeff Scott Brown Nov 05 '18 at 01:27
  • That `geometry(Point,4326)` isn't going to be recognized by the db. – Jeff Scott Brown Nov 05 '18 at 01:34
  • The point_test table is not created at all. The creation of the entire table is skipped. I'll try with H2 and get back to you. I do want the column set up with SRID 4326, though. – Anonymous1 Nov 05 '18 at 02:23
  • In the course of double checking with H2, I realized I had an incorrect path for the Sql Server dialect. The correct path is org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect. After correcting that path, I get the following: create table point_test (id bigint identity not null, version bigint not null, coords GEOMETRY not null, primary key (id)). I'm not sure how to get it to use SRID 4326, but it's possible I need to do that per object at initialization. – Anonymous1 Nov 05 '18 at 03:24
  • The SRID is set per object at initialization, so that answers all my questions. Thanks for your help! – Anonymous1 Nov 05 '18 at 03:53

1 Answers1

2
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.

Anonymous1
  • 3,877
  • 3
  • 28
  • 42