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

  • 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

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