Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Spatial - 'Invalid endian flag value encountered' Exception

I'm trying to run a simple query in Hibernate Spatial 4.0 on PostgreSQL 9.3. I have a number of objects in a table with latitude/longitude values, and I'm trying to query objects that fall within a given radius of a particular latitude/longitude. The geometry values seem to be persisted without any problem, and are defined like this in my entity class:

@Column(columnDefinition = "Geometry", nullable = true)
@Type(type = "org.hibernate.spatial.GeometryType")
private Point coordinates = null;

I don't have any errors when persisting objects with the coordinates value set. However, when I run a query, I see the following Exception:

    javax.servlet.ServletException: javax.servlet.ServletException: javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet

    <snip />

org.postgresql.util.PSQLException: ERROR: Invalid endian flag value encountered.
    org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
    org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
    org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
    org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
    org.hibernate.loader.Loader.getResultSet(Loader.java:2031)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1832)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
    org.hibernate.loader.Loader.doQuery(Loader.java:899)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
    org.hibernate.loader.Loader.doList(Loader.java:2516)
    org.hibernate.loader.Loader.doList(Loader.java:2502)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
    org.hibernate.loader.Loader.list(Loader.java:2327)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
    org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
    org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
    org.hibernate.internal.SessionImpl.list(SessionImpl.java:1268)
    org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264)

The query I'm running looks like this:

Query query = this.entityManager
        .createQuery(
                "SELECT v FROM MyEntity v WHERE within(v.coordinates, :filter) = true",
                MyEntity.class);
query.setParameter("filter", point);

I came across this question on StackOverflow that mentions the same error, but I'm declaring my coordinates property the same way that is mentioned in the answer and still get this error.

For the record, I've tried using PostGIS 1.5.2 and PostGIS 2.1.0. I've also tried different version of my PostgreSQL JDBC driver, from 8.4 to 9.3. Regardless of the library version I still encounter this issue.

Can anyone shed any light on what could be happening here? Is my query wrong? Is my property not defined correctly? Is there something else I should be trying? I'm completely stuck and at a loss for what could be the issue here. Any advice would be GREATLY appreciated.

like image 855
Shadowman Avatar asked Nov 19 '13 19:11

Shadowman


1 Answers

Try this:

@Column(columnDefinition="Geometry")
@Type(type = "org.hibernatespatial.GeometryUserType")
private Point point;
like image 86
SergeyB Avatar answered Nov 05 '22 05:11

SergeyB