I'm having some issues integrating these 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 annotation is:
@NotNull
@Column(columnDefinition="Geometry")
@Type(type="org.hibernate.spatial.GeometryType")
private Point geom;
And the Point creation example is:
Location location = new Location();
WKTReader fromText = new WKTReader();
Point geom = null;
try {
geom = (Point) fromText.read("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());
}
location.setGeom(geom);
locationDAO.insert(location);
Best Answer
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:
Postgis jdbc is the extension to postgresql jdbc that you need.
mvn package
in thejava/jdbc
directory. Read its readme.lib
directoryjdbc:postgresql_postGIS://localhost:5432/mydatabase
. Notice thepostgresql_postGIS
part. I also changed the driver class toorg.postgis.DriverWrapper
. This is a wrapper that registers postgis types with the native jdbc.Here's my final resource configuration in tomcat:
This procedure is generally described in the postgis jdbc's README. So make sure you read it.