Using JPA & Hibernate with PostGIS

December 18, 2009

I have always strived to write code that is not tied to a particular technology or platform. Abstracting code from the underlying database is probably the killer example and thankfully over the past few years the Java Persistence API (JPA) standard has evolved through the Java community to make this possible.

JPA is a standard interface for storing objects containing data into a relational database. The standard defines interfaces for annotating Java objects, retrieving objects using queries, and interacting with a database using transactions. An application that uses the JPA interface can work with different databases without using any vendor-specific database code thereby making it easy to port between different database vendors.

In the past I have used the open source Toplink Essentials (by Oracle) implementation with great success.  An alternative implementation spawned from the JBOSS world is Hibernate.  Of great significance in our quest to deal with geographic data is Hibernate Spatial – a generic extension to Hibernate that 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.

To use Hibernate Spatial you first need to get Hibernate and the Java Topology Suite.  Hibernate provides the ORM functionality, and the Java Topology Suite provides the Geometry (and related) types. Hibernate Spatial is the glue between them.

A first rate tutorial on how to get Hibernate Spatial working can be found here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: