Welcome to Hibernate Spatial

Hibernate Spatial is a generic extension to Hibernate for handling geographic data. Hibernate Spatial is open source and licensed, like Hibernate, under the LGPL license.

Hibernate Spatial allows you to deal with geographic data in a standardized way. It abstracts away from the specific way your database supports geographic data, and provides a standardized, cross-database interface to geographic data storage and query functions.

Hibernate Spatial supports most of the functions of the OGC Simple Feature Specification. Supported databases are: Oracle 10g/11g, Postgresql/Postgis, MySQL, Microsoft SQL Server and H2/GeoDB.

There is a similar project for NHibernate: NHibernate.Spatial.

Compatibility with Hibernate ORM

  • Hibernate Spatial version 1.0 is compatible with Hibernate 3.2.x - 3.5.x
  • Hibernate Spatial version 1.1.x is compatible with Hibernate 3.6.x
  • Hibernate Spatial version 4.0 is compatible with Hibernate 4.x

Hibernate Spatial moving to Hibernate ORM

We are currently working on migrating Hibernate Spatial to a module of the Hibernate ORM project. The move will be complete by the time of the Hibernate 5 release.

The Hibernate Spatial Release 4 will be therefore be the last release that is made independently of Hibernate.

We decided to base the release for Hibernate 4 on the new code for Hibernate 5 (hence the jump in version numberering). This code is quite differently organised as the code for Hibernate spatial 1.x. The most visible differences are:

  • package org.hibernatespatial is now org.hibernate.spatial
  • only one jar needed: all dialects are now included in the base package
  • GeometryUserType is replaced by GeometryType

See the new tutorial for Hibernate Spatial 4 for more information.

For Oracle users: custom ConnectionFinders are not (yet) supported in version 4.0-M1. This will be fixed soon.

Features

Hibernate Spatial uses the Java Topology Suite (JTS) as its geometry model. JTS is an implementation of the OpenGIS Simple Features Implementation Specification for SQLv. 1.1 (SFS). This specification is implemented in most RDBMS with spatial data support. It is also a direct precursor to a precursor to SQL/MM Part 3: Spatial (ISO/IEC 13249-3).

The SFS specification defines a set of functions on geometries. Hibernate Spatial makes a subset of these functions available in HQL and in the criteria query API (see the SpatialRestrictions class in the org.hibernatespatial.criterion package).

Not all databases support all the functions defined by Hibernate Spatial. The table below provides an overview of the functions provided by each database

FunctionDescriptionPostgresqlOracle 10g/11gMySQLSQLServerGeoDB (H2)
Basic functions on Geometry
int dimension(Geometry)SFS §2.1.1.1 OKOKOKOKNOK
String geometrytype(Geometry)SFS §2.1.1.1 OKOKOKOKOK
int srid(Geometry) SFS §2.1.1.1 OKOKOKOKOK
Geometry envelope(Geometry)SFS §2.1.1.1 OKOKOKOKOK
String astext(Geometry)SFS §2.1.1.1 OKOKOKOKOK
byte[] asbinary(Geometry)SFS §2.1.1.1 OKOKOKOKOK
boolean isempty(Geometry)SFS §2.1.1.1 OKOKOKOKOK
boolean issimple(Geometry)SFS §2.1.1.1 OKOKOKOKOK
Geometry boundary(Geometry)SFS §2.1.1.1 OKOKNOKOKNOK
Functions for testing Spatial Relations between geometric objects
boolean equals(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean disjoint(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean intersects(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean touches(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean crosses(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean within(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean contains(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean overlaps(Geometry, Geometry)SFS §2.1.1.2 OKOKOKOKOK
boolean relate(Geometry, Geometry, String) SFS §2.1.1.2 OKOKNOKOKNOK
Functions that support Spatial Analysis
double distance(Geometry, Geometry)SFS §2.1.1.3 OKOKNOKOKNOK
Geometry buffer(Geometry, double)SFS §2.1.1.3 OKOKNOKOKOK
Geometry convexhull(Geometry)SFS §2.1.1.3 OKOKNOKOKNOK
Geometry intersection(Geometry, Geometry)SFS §2.1.1.3 OKOKNOKOKNOK
Geometry geomunion(Geometry, Geometry)SFS §2.1.1.3 (renamed from union)OKOKNOKOKNOK
Geometry difference(Geometry, Geometry)SFS §2.1.1.3 OKOKNOKOKNOK
Geometry symdifference(Geometry, Geometry)SFS §2.1.1.3 OKOKNOKOKNOK
Common non-SFS functions
boolean dwithin(Geometry, Geometry, double)Returns true if the geometries are within the specified distance of one anotherOKNOKNOKNOKOK
Geometry transform(Geometry, int)Returns a new geometry with its coordinates transformed to the SRID referenced by the integer parameterOKOKNOKNOKNOK
Spatial aggregate Functions
Geometry extent(Geometry)Returns a bounding box that bounds the set of returned geometriesOKOKNOKNOKNOK