Given the query example here: http://www.hibernatespatial.org/tutorial-hs4.html
Query query = em.createQuery("select e from Event e where within(e.location, :filter) = true", Event.class);
query.setParameter("filter", filter);
Is it possible to rewrite the query using jpa 2 criteria api?( I am unsure how i should deal with the within(e.location, :filter)
part.
I recently work at the exact same problem. My solution is a own Predicate for the within-keyword.
Your query would look like this:
JPA does not support spatial. However, you can unwrap the hibernate session from your JPA EntityManager and run spatial criteria.
The lat lon bounds in this code sample is arbitrary.
Here is some more code not directly related to the question. This class can be used as an "Order" criteria to be added to a hibernate criteria. It will sort results by distance from the argument location: