Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate spatial functions keep throwing unexpected AST node

I'm trying to query spatial relations between my entities but keep getting this exception:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: ( near line 1,

My entities are working properly, so is the mapping. I believe that my query has the issue:

SELECT r FROM Regiao r, Imovel i WHERE r.nivel = :nivel AND contains(r.regiao, i.latlng)

Where both r.regiao and i.latln are GeometryType mapped (one being a Polygon and the other one a Point.

Ps.: As I asked the question I finally understood the issue.

like image 325
Moa Avatar asked Oct 30 '14 13:10

Moa


2 Answers

Apparently the syntax of spatial functions requires you to test it against boolean values so I had to add the comparison in the end of my query:

SELECT r FROM Regiao r, Imovel i WHERE r.nivel = :nivel AND contains(r.regiao, i.latlng) = TRUE
like image 199
Moa Avatar answered Sep 22 '22 08:09

Moa


For me this didn't seem to solve a similar problem. I reverted to using Criteria with a SpatialRestriction to solve my problem. This example searches all Regions that contain a given location where location here is a Geometry.

Criteria criteria = getCurrentSession().createCriteria(Region.class);
criteria.add(SpatialRestrictions.contains("theGeom", location));
like image 42
gorik Avatar answered Sep 18 '22 08:09

gorik