2
我有下面的查询。本机SQL查询到Spring JPA命名查询
SELECT zip, primary_city, latitude, longitude,
111.045* DEGREES(ACOS(COS(RADIANS(latpoint))
* COS(RADIANS(latitude))
* COS(RADIANS(longpoint) - RADIANS(longitude))
+ SIN(RADIANS(latpoint))
* SIN(RADIANS(latitude)))) AS distance_in_km
FROM zip
JOIN (
SELECT 42.81 AS latpoint, -70.81 AS longpoint
) AS p ON 1=1
ORDER BY distance_in_km
LIMIT 15
当我执行在SQL编辑器我是从压缩表中获取拉链,primary_city,纬度,经度,distance_in_km上面的查询。
我需要在我的JPA repository中使用相同的名称。我尝试使用命名查询,但它显示验证失败exception.Also在只有 zip,primary_city,latitude,longitude(四个属性)的实体类zip.java中。我需要决定如何捕捉distance_in_km它来自ResultSet中 请帮助我如何实现相同的春天JPA
distance_in_km将作为查询执行的结果。因此,如何在实体类 – Ramkumar 2015-02-11 08:51:50
中定义这些变量您需要使用[projection](https://access.redhat.com/documentation/en-US /JBoss_Enterprise_Web_Server/1.0/html/Hibernate_Core_Reference_Guide/querycriteria-projection.html)。如果您使用DTO,则更容易,但您也可以使用实体(尽管您必须选择比您可能需要的列更多的列)。 – 2015-02-11 08:59:21
distance_in_km列在表格中并不存在,它会在我们根据计算执行查询时出现。因此,是否需要为resulset定义一个或多个实体?是否有其他方法来定义 – Ramkumar 2015-02-11 09:06:00