I'm trying to persist a com.vividsolutions.jts.geom.Polygon
in my PostgreSQL (with PostGIS enabled) database, using Hibernate and Hibernate-Spatial plugin.
Caused by: org.postgresql.util.PSQLException: One can not infer the SQL type to use for an instance of org.postgis.PGgeometry
It fired the below exception. What am I doing wrong?
My pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>${version.hibernate.spatial}</version> //version 4.3
<exclusions>
<exclusion>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</exclusion>
<exclusion>
<groupId>org.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>${version.vividsolutions.jts}</version> //version 1.13
</dependency>
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>${version.jdbc.postgis.version}</version> //version 2.1.3
</dependency>
persistence.xml
<persistence-unit name="Test-PU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/testDS</jta-data-source>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<!-- Debug -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.generate_statistics" value="true" />
...
My module in Wildfly
modules/org/postgresql/main
module.xml
postgis-jdbc-2.1.3.jar
postgresql-9.3-1101.jdbc4.jar
standalone.xml
<datasource jndi-name="java:jboss/datasources/testDS" pool-name="testDS" enabled="true"
use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/testDB</connection-url>
<driver>postgresql-driver</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<driver name="postgresql-driver" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
Mapping
@Column(name = "perimeter", columnDefinition = "Geometry")
@Type(type = "org.hibernate.spatial.GeometryType")
private Polygon perimeter;
Best Answer
Looks like you are missing hibernate spatial in your pom.xml
Here is the pom I used with PostGIS and Hibernate spatial
https://github.com/thesteve0/parkshibernatespatial/blob/master/pom.xml