我正在使用 sql 结果集映射来映射本机查询的结果。但我面临许多编译时问题。告诉我我在下面所做的方法是否正确?我的实体类:实体类地点:
@EnableCaching
@Entity
@Table(name = "Table")
@NamedNativeQuery(
name = "findPlace",
query = "SELECT P.code,P.name,P.latitude,P.longitute,"
+"111.045* DEGREES (ACOS(COS(RADIANS(latpoint))"
+"*COS (RADIANS(P.latitude))"
+"*COS(RADIANS(longpoint) - RADIANS (P.longitute))"
+" SIN (RADIANS (latpoint))"
+"*SIN (RADIANS(P.latitude)))) As distance_in_km"
+"FROM table P"
+"JOIN("
+"SELECT :latitude AS latpoint , :longitute AS longpoint)"
+"AS p ON 1=1"
+"ORDER BY distance_in_km"
+"LIMIT 1", "locationResult")
@SqlResultSetMapping(name = "locationResult",
columns = { @ColumnResult(name = "code"),
@ColumnResult(name = "name"),
@ColumnResult(name = "latitude"),
@ColumnResult(name = "longitute"),
@ColumnResult(name = "distance_in_km")
})
public class Place {
public Place() {
}
@Id
@Column(name = "CODE")
private String iata;
@Column(name = "NAME")
private String name;
@Column(name = "PLACE_CODE")
private String placeCode;
@Column(name = "PLACE_NAME")
private String placeName;
@Column(name = "STATE_CODE")
private String stateCode;
@Column(name = "STATE_NAME")
private String stateName;
@Column(name = "TEST1")
private boolean test;
@Column(name = "TEST2")
private boolean test2;
@Column(name = "latitude")
private boolean latitude;
@Column(name = "longitute")
private boolean longitute;
}
我的 JPA 存储库类:
@Repository
public interface PlaceRepository extends JpaRepository<Place, Long> {
@Query(findPlace)
Place findBylattitudeAndlongitute(@Param("latitude") String latitude ,@Param("longitute") String longitute );
}
我正在开发基于 spring jpa 的应用程序,所以我在配置类中定义了所有 jpa 配置(实体管理器、事务等)。
帮我解决上述问题。