Hibernate Spatial Grails Plugin
Dependency :
compile ":hibernate-spatial:0.0.4"
Summary
Installation
One of the following:
Project at GitHub is grails-hibernate-spatial-plugin
grails install-plugin hibernate-spatial-hdb
grails install-plugin hibernate-spatial-mysql
grails install-plugin hibernate-spatial-oracle
grails install-plugin hibernate-spatial-postgresql
grails install-plugin hibernate-spatial-sqlserver
Description
It provides support for using the Hibernate Spatial in Grails.
How it works
The core plugin is not for direct use. There is a child plugin for each Provider supported by Hibernate Spatial:- hibernate-spatial-hdb for H2/GeoDB;
- hibernate-spatial-mysql for MySQL;
- hibernate-spatial-oracle for Oracle 10g (or superior);
- hibernate-spatial-postgresql for PostgreSQL/PostGIS;
- hibernate-spatial-sqlserver for Microsoft SQL Server.
- Register new Hibernate custom user types in Config.groovy;
/* Added by the Hibernate Spatial Plugin. */
grails.gorm.default.mapping = {
'user-type'(type:org.hibernatespatial.GeometryUserType, class:com.vividsolutions.jts.geom.Geometry)
'user-type'(type:org.hibernatespatial.GeometryUserType, class:com.vividsolutions.jts.geom.GeometryCollection)
// Additional user-type mappings
}- Change the Hibernate Dialect and the JDBC Driver class in DataSource(s).groovy;
/* Added by the Hibernate Spatial Plugin. */
dataSource {
driverClassName = // Suitable JDBC Driver
dialect = // Suitable Hibernate Spatial Dialect
}- Define repositories and resolve library dependencies.
// plugin's BuildConfig.groovy
repositories {
// (...) mavenRepo 'http://download.osgeo.org/webdav/geotools'
mavenRepo 'http://www.hibernatespatial.org/repository'
}dependencies {
// Suitable dependencies for this Provider
}Basic usage
- Install the appropriate child plugin;
- Create a spatially enabled database;
- Configure the corresponding JDBC Driver dependency in BuildConfig.groovy;
- Change the JDBC URL in DataSource(s).groovy;
- In your domain classes, define properties of the type com.vividsolutions.jts.geom.Geometry (or subclasses);
- Perform some tests using save, dynamic finders, HQL and Criteria.