How to translate this MySQL query into Hibernate-Query

I would like to ask how to translate this MySQL query into a Hibernate query:

SELECT * FROM Cities WHERE WITHIN(GeomFromText('POINT(52.5 13.3)'), polygon); 

or

 SELECT * FROM Cities WHERE MBRContains(polygon, GeomFromText('POINT(52.5 13.3)'); 

Thanks. Thomas

+4
source share
1 answer

Got this:

 import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; import javax.persistence.Query; Coordinate coord = new Coordinate(52.5, 13.3); Point point = new GeometryFactory().createPoint(coord); Query query = em.createQuery("FROM Cities WHERE WITHIN(:location, polygon) = true", Cities.class); query.setParameter("location", point); 
+6
source

Source: https://habr.com/ru/post/1436719/


All Articles