I'm running into the same problem. Although my configuration is a little bit different. I'm using Hibernate 5.1
Here are the details:
The entity class:
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Polygon;
@Entity
public class PontodeInteresse implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String descricao;
private Point ponto;
private LineString linha;
private Geometry geometry;
private Polygon poligono;
/* Getters and setters */
I can insert a Polygon from code. Everything seems to be fine:
public void criarGeometry () {
PontodeInteresse ponto = new PontodeInteresse();
GeometryFactory gf = new GeometryFactory();
LinearRing shell = gf.createLinearRing(new Coordinate[] {
new Coordinate(-43.5552982, -22.8839067), new Coordinate(-43.5556591, -22.8838402),
new Coordinate(-43.5554786, -22.8829425), new Coordinate(-43.5555869, -22.8824438),
new Coordinate(-43.5552982, -22.8839067)});
LinearRing[] holes = new LinearRing[0];
Polygon polygon = gf.createPolygon(shell, holes);
ponto.setGeometry(polygon);
colocar(ponto);
}
But, when I try to run a simple geospatial query from the method testar() (below), I get the "Invalid endian flag value encountered" error. I have already tried to use @Column and set the geo types, but got no luck. The very same error happens if I try to run this query from PgAdmin:
SELECT ST_AsGeoJSON(ST_GeomFromWKB(geometry)) from pontodeinteresse;
public void testar() {
try {
GeometryFactory gf = new GeometryFactory();
Point pontoDentro = gf.createPoint( new Coordinate(-43.5658, -22.8722) );
PontodeInteresse bairro = null;
bairro = (PontodeInteresse) entityManager.createQuery("select p from PontodeInteresse p where contains(p.geometry, :ponto) = true").setParameter("ponto",pontoDentro).getSingleResult();
if (bairro != null) {
resultado = "OK";
} else {
resultado = "ERRO";
}//if
} catch(Exception e) {
System.out.println(e.getMessage());
}//try
}
POM dependencies included:
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
The persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/ ... ce_2_0.xsd">
<persistence-unit name="projetoX_PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jboss/datasources/projectNameDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
</properties>
</persistence-unit>
</persistence>
Thanks is advance