3

I'm attempting to integrate Spring Roo with a PostGIS-enabled PostgreSQL database via Hibernate, following the Hibernate Spatial tutorial. All of the non-GIS stuff is working fine, and I've created a DB from a PostGIS template.

The problem is that as soon as I add a Geometry property to one of my entities:

@Type(type="org.hibernate.spatial.GeometryType")
private Point centerPoint;

... it builds okay, but attempting to run on the server (and actually interact with the DB) causes the error below:

Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 3000
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:77)
    at org.hibernate.dialect.TypeNames.get(TypeNames.java:100)
    at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:298)
    at org.hibernate.mapping.Column.getSqlType(Column.java:208)
    at org.hibernate.mapping.Table.sqlCreateString(Table.java:418)
    at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:1099)
    at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:106)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:372)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
    ... 41 more

Hibernate Spatial's dependencies seem to suggest that postgis-jdbc 1.5.3 is required but 1.5.3 is not present in any Maven repositories and I can't get it to compile from source. I've tried 1.5.2 and 1.3.3, and both result in the same 3000 error. HS says 1.5.3 should be "provided", but setting the dependency to 1.5.3 and <scope>provided</scope> doesn't help either.

Is this simply a case of needing a precise version of the JDBC, or is something else wrong?

The relevant extract of my POM is as follows:

        <dependency>
            <groupId>com.vividsolutions</groupId>
            <artifactId>jts</artifactId>
            <version>1.12</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-spatial</artifactId>
            <version>4.0-M1</version>
        </dependency>
        <dependency>
            <groupId>org.postgis</groupId>
            <artifactId>postgis-jdbc</artifactId>
            <version>1.5.2</version>
        </dependency>

And from persistence.xml:

<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
orlade
  • 2,060
  • 4
  • 24
  • 35

2 Answers2

5

Your exception means that Postgresql dialect can't support the data type you have provided by annotation. Extending it with a custom class to add support could be a way to solve your problem.

I've look at the GIS project, do you provide javassist dependency with compile scope too ?

Did you try to reference your data types with the following annotations? See https://stackoverflow.com/a/3047190/390462.

@Column(name = "geometry", columnDefinition="Geometry", nullable = true) 
private Geometry geometry;

As much as I have understood, you need to give a columnDefinition to your field, otherwise it would not be able to map the field to the good db column.

Community
  • 1
  • 1
BendaThierry.com
  • 2,080
  • 1
  • 15
  • 17
  • Regarding the dialect, I forgot to mention that it's the same problem with the default `PostgreSQLDialect` and the correct `org.hibernate.spatial.dialect.postgis.PostgisDialect`, so there's that. I hadn't added the javassist dependency, since it should be included transitively. Unfortunately manually adding the dependency to the POM makes no difference :(. I was following the tutorial at http://www.hibernatespatial.org/tutorial-hs4.html and did all of that stuff, so I'm hoping to get away without any custom classes. – orlade Aug 28 '12 at 10:28
  • Having a look at these tutorial. It seems you are using a Milestone version of the lib hibernate-spatial with a lower version of their postgis-jdbc package: try to use 1.5.3. Sometimes it becomes magical. – BendaThierry.com Aug 28 '12 at 10:39
  • Sigh. So I finally managed to get the PostGIS JDBC 1.5.3 to compile using Ant, and I copied it into the corresponding Maven repository directory and updated my POM postgis-jdbc version to 1.5.3, and lo and behold it didn't complain! It picked it up, and it was listed in the Maven Dependencies library. However I still get exactly the same error. – orlade Aug 28 '12 at 12:37
  • 1
    Ok, maybe [these answer](http://stackoverflow.com/a/3047190/390462) of Pascal Thivent will help you. – BendaThierry.com Aug 28 '12 at 14:48
  • 1
    You know what, that may just have worked! I already saw that question, but it seemed like reverting to Hibernate annotations directly was moving way from a Roo solution. I'll do a couple of tests to confirm, but thanks much for the pointer. – orlade Aug 29 '12 at 01:39
  • 1
    This certainly seems to have resolved this problem, and I can now manage to convert Strings to Geometry, but now they don't write to the database properly. [But that's another question](http://stackoverflow.com/questions/12215212/postgis-geometry-saving-invalid-endian-flag). – orlade Aug 31 '12 at 12:24
0

I found solution!

(Grails, Hibernate Spatial 4.3, Config.groovy)

hibernate {
    // ...
    dialect = 'org.hibernate.spatial.dialect.postgis.PostgisDialect'
}
AndreyT
  • 1,449
  • 1
  • 15
  • 28