2012-09-27 103 views
4

我想請問如何這個MySQL查詢翻譯成一個Hibernate查詢:如何這個MySQL查詢轉換成一個Hibernate查詢

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

或本

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

謝謝。 托馬斯

+0

做這些條款意味着'WITHIN(GeomFromText( 'POINT(52.5 13.3)'),多邊形);'和'MBRContains(多邊形,GeomFromText('POINT(52.5 13.3)'); '? – Lion

+0

http://dev.mysql.com/doc/refman/5.1/en/geometry-property-functions.html –

+0

我不認爲原生Hibernate會做,但檢出http:// www.hibernatespatial.org/ – gtgaxiola

回答

6

明白了:

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); 
+1

感謝您的回答,不要忘記接受它。 – Lion

相關問題