Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having some issues integratings this technologies:

  • Hibernate Spatial 4.0-M1
  • Postgis 2.0.2 (with compiled jdbc 2.0.2)
  • Hibernate 4.1.1

The specific error is:

Caused by: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgis.PGgeometry. Use setObject() with an explicit Types value to specify the type to use.

The entity anotation is:

private Point geom;

And the Point creation example is:

Location location = new Location();
WKTReader fromText = new WKTReader();
Point geom = null;
try {
    geom = (Point)"POINT(-56.2564083434446 -34.8982159791812)");
} catch (ParseException e) {
    throw new RuntimeException("Not a WKT string:" + "SRID=4326;POINT(-56.2564083434446 -34.8982159791812)");
if (!geom.getGeometryType().equals("Point")) {
    throw new RuntimeException("Geometry must be a point. Got a " + geom.getGeometryType());


share|improve this question
up vote 5 down vote accepted

I was using Tomcat, and it's connection pooling facilities. I just exposed a datasource to my application through JNDI.

Here's what did work for me:

  • When I included the maven dependency for hibernate-spatial, it has a transitive dependency for hibernate itself, postgresql's jdbc and postgis's jdbc. So what I did was to remove these dependencies (outdated). My pom looks like this:

Postgis jdbc is the extension to postgresql jdbc that you need.

  • Then I cloned postgis repository and compiled their jdbc extension. Just run mvn package in the java/jdbc directory. Read its readme.
  • Then I placed the most recent postgresql-jdbc and the recently compiled postgis jdbc in the tomcat's lib directory
  • On the tomcat's server configuration, I changed the database url to jdbc:postgresql_postGIS://localhost:5432/mydatabase. Notice the postgresql_postGIS part. I also changed the driver class to org.postgis.DriverWrapper. This is a wrapper that registers postgis types with the native jdbc.

Here's my final resource configuration in tomcat:

<Resource auth="Container"
          maxActive="120" maxIdle="10" name="jdbc/myapp"
          username="myuser" password="mypassword"
          poolPreparedStatements="true" type="javax.sql.DataSource" 
          validatingQuery="select 1"

This procedure is generally described in the postgis jdbc's README. So make sure you read it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.