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.
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:
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.
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
|Function||Description||Postgresql||Oracle 10g/11g||MySQL||SQLServer||GeoDB (H2)|
|Basic functions on Geometry|
|int dimension(Geometry)||SFS §184.108.40.206|
|String geometrytype(Geometry)||SFS §220.127.116.11|
|int srid(Geometry)||SFS §18.104.22.168|
|Geometry envelope(Geometry)||SFS §22.214.171.124|
|String astext(Geometry)||SFS §126.96.36.199|
|byte asbinary(Geometry)||SFS §188.8.131.52|
|boolean isempty(Geometry)||SFS §184.108.40.206|
|boolean issimple(Geometry)||SFS §220.127.116.11|
|Geometry boundary(Geometry)||SFS §18.104.22.168|
|Functions for testing Spatial Relations between geometric objects|
|boolean equals(Geometry, Geometry)||SFS §22.214.171.124|
|boolean disjoint(Geometry, Geometry)||SFS §126.96.36.199|
|boolean intersects(Geometry, Geometry)||SFS §188.8.131.52|
|boolean touches(Geometry, Geometry)||SFS §184.108.40.206|
|boolean crosses(Geometry, Geometry)||SFS §220.127.116.11|
|boolean within(Geometry, Geometry)||SFS §18.104.22.168|
|boolean contains(Geometry, Geometry)||SFS §22.214.171.124|
|boolean overlaps(Geometry, Geometry)||SFS §126.96.36.199|
|boolean relate(Geometry, Geometry, String)||SFS §188.8.131.52|
|Functions that support Spatial Analysis|
|double distance(Geometry, Geometry)||SFS §184.108.40.206|
|Geometry buffer(Geometry, double)||SFS §220.127.116.11|
|Geometry convexhull(Geometry)||SFS §18.104.22.168|
|Geometry intersection(Geometry, Geometry)||SFS §22.214.171.124|
|Geometry geomunion(Geometry, Geometry)||SFS §126.96.36.199 (renamed from union)|
|Geometry difference(Geometry, Geometry)||SFS §188.8.131.52|
|Geometry symdifference(Geometry, Geometry)||SFS §184.108.40.206|
|Common non-SFS functions|
|boolean dwithin(Geometry, Geometry, double)||Returns true if the geometries are within the specified distance of one another|
|Geometry transform(Geometry, int)||Returns a new geometry with its coordinates transformed to the SRID referenced by the integer parameter|
|Spatial aggregate Functions|
|Geometry extent(Geometry)||Returns a bounding box that bounds the set of returned geometries|