如何编写休眠空间查询?

how to write hibernate spatial query?

这是homePage.jsp代码:

<button id="bilgial" onclick="getVector(id)">Get Vector</button> <input type="text" id="hs">

这是 getVector(id) 函数:

 var id = document.getElementById("hs").value;
function getVector(id) {

    ajax({
        type: "GET",
        path: "/getGeoJson",
        data: {id: id},
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        success: function (data) {
            var parser = new OpenLayers.Format.GeoJSON();
            var feature = parser.read(data.data);
            if (feature.length != 0) {
                feature[0].attributes.id = data.id;
            }
            vectors.addFeatures(feature);
        }
    });
}

这是我的控制器获取方法:

@Controller
public class HSpatialController  {

SavegeojsonManager add = new SavegeojsonManager();

@RequestMapping(value = "/getGeoJson", method = RequestMethod.GET)
@ResponseBody
public GeoJSON getGeoJson( final HttpServletRequest request,@RequestParam("id") final String vectorId) {
    return add.get(vectorId);
}

}

这是 SavegeojsonManager class 和获取方法:

 public GeoJSON get(String id) {

    GeoJSON geoJson = new GeoJSON();
    EntityManager em = HibernateSpatialJPA.createEntityManager();
    em.getTransaction().begin();
    Query query = em.createQuery("select e from SavegeojsonEntity  ????")
   query.setParameter("", ??);
    return geoJson;
}

否则我该怎么办?

我想吃数据库中的数字,你想从 TextBox 中获取数据与数据 GetData 一样?

所以代码应该是这样的:

 public GeoJSON get(String id) {
        GeoJSON geoJson = new GeoJSON();
        EntityManager em = HibernateSpatialJPA.createEntityManager();
        em.getTransaction().begin();
        Query query = em.createQuery("from SavegeojsonEntity s where s.id = :id")
        query.setParameter("id", Integer.valueOf(id));
        List entityList = query.getResultList();
        if(entityList != null && !entityList.isEmpty()){
            SavegeojsonEntity entity = (SavegeojsonEntity)entityList.get(0);
            geoJson.setType(entity.getVectorType());
            if(entity.getVectorType().equals("Point")){
                geoJson.setData(entity.getPoint());//or entity.getXXX() since you need to get point data,
            } else if(...){
                //same for Polygon/MultiPolygon/StringLine and so on
            }
        }
        em.getTransaction().close();
        return geoJson;
 }