NullPointerException at com.mysema.query.types.Templates.getPrecedence(Templates.java:329)

634 views
Skip to first unread message

Rob Shepherd

unread,
Nov 2, 2015, 6:33:28 PM11/2/15
to Querydsl
Hi QueryDSL Users,

I'm hitting a NPE.  It's more than likely that I've done something wrong, but maybe somebody can pick my mistakes.

I'm using QueryDSL 3.6.9 with PostgreSQL 9 and Postgis, with the querydsl-spatial extension.

QueryDSL has correctly picked up that I'm using JTS types as per Hibernate-spatial.

here is my query: it's just a prototype at present

JPAQuery query = new JPAQuery(entityManager).from(QThing.thing);
int dist = 250000;
com
.vividsolutions.jts.geom.Point p = G.mkPoint(-4, 53);
Expression<Geometry> e = Expressions.constant(p);
query
= query.where(QThing.thing.point.distanceSphere(e).lt(dist) );
return query.list(QThing.thing); <--NPE in here


Does anybody have any pointers why I might be getting this error?


java.lang.NullPointerException: null
 at com
.mysema.query.types.Templates.getPrecedence(Templates.java:329) ~[querydsl-core-3.6.9.jar:na]
 at com
.mysema.query.support.SerializerBase.visitOperation(SerializerBase.java:272) ~[querydsl-core-3.6.9.jar:na]
 at com
.mysema.query.jpa.JPQLSerializer.visitOperation(JPQLSerializer.java:445) ~[querydsl-jpa-3.6.9.jar:na]
 at com
.mysema.query.support.SerializerBase.visit(SerializerBase.java:242) ~[querydsl-core-3.6.9.jar:na]
 at com
.mysema.query.support.SerializerBase.visit(SerializerBase.java:32) ~[querydsl-core-3.6.9.jar:na]
 at com
.mysema.query.types.OperationImpl.accept(OperationImpl.java:88) ~[querydsl-core-3.6.9.jar:na]
 at com
.mysema.query.support.SerializerBase.handle(SerializerBase.java:98) ~[querydsl-core-3.6.9.jar:na]
 at com
.mysema.query.jpa.JPQLSerializer.serialize(JPQLSerializer.java:215) ~[querydsl-jpa-3.6.9.jar:na]
 at com
.mysema.query.jpa.JPAQueryBase.serialize(JPAQueryBase.java:63) ~[querydsl-jpa-3.6.9.jar:na]
 at com
.mysema.query.jpa.JPAQueryBase.serialize(JPAQueryBase.java:53) ~[querydsl-jpa-3.6.9.jar:na]
 at com
.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:126) ~[querydsl-jpa-3.6.9.jar:na]
 at com
.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:96) ~[querydsl-jpa-3.6.9.jar:na]
 at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:248) ~[querydsl-jpa-3.6.9.jar:na]




Thanks


Rob

Rob Shepherd

unread,
Nov 4, 2015, 8:42:24 AM11/4/15
to Querydsl
It turns out that various JTS functions are defined (in com/querydsl/spatial/jts/JTSGeometryExpression.java ) for distance operations:

public NumberExpression<Double> distance(Expression<? extends Geometry> geometry) {
   
return Expressions.numberOperation(Double.class, SpatialOps.DISTANCE, mixin, geometry);
}


public NumberExpression<Double> distanceSphere(Expression<? extends Geometry> geometry) {
   
return Expressions.numberOperation(Double.class, SpatialOps.DISTANCE_SPHERE, mixin, geometry);
}


public NumberExpression<Double> distanceSpheroid(Expression<? extends Geometry> geometry) {
   
return Expressions.numberOperation(Double.class, SpatialOps.DISTANCE_SPHEROID, mixin, geometry);
}

But only one of these is registered underneath in Hibernate 

ops.put(SpatialOps.DISTANCE, "distance({0}, {1})");


So this will never work as hibernate-spatial doesn't seem to support Distance_Spheroid/Sphere.

I'll have a bash at registering some HQL functions for these and exposing them myself through the QueryDelegate.

timowest

unread,
Nov 4, 2015, 11:18:39 AM11/4/15
to Querydsl
Could you create an issue for it on GitHub?

Rob Shepherd

unread,
Nov 4, 2015, 7:03:39 PM11/4/15
to Querydsl


On Wednesday, 4 November 2015 16:18:39 UTC, timowest wrote:
Could you create an issue for it on GitHub?



I'm just doing that.  In fact, I'm also trying to get working support for ST_DWithin(geom,geom,dist)     (which isn't exposed as part of the GeometryExpression QType, but is available as a standalone Expression. 

If I try and use that in QueryDSL-JPA, it's a similar (but I think subtly different) issue: 

It appears that QueryDSL-JPA uses HibernateSpatial which uses JTS

but QueryDSL-SQL uses a PostgreSQL adapter which uses geolatte.

Seemingly there is mixed support for the range of potential operations over these two approaches on top of the native "capability" of the underlying spatial database library.

I am trying to get to grips with the codebase, and would happily submit a pull request from a fork, but I may need a few pointers on the architecture.

Thanks

Rob
 
Reply all
Reply to author
Forward
0 new messages