I am using sql resultset mapping to map the result from native query.But i am facing many compile time issues. Advise me whether the approach that i did below is correcet or not? My entity class: Entity class Place:
@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;
}
My JPA repository class:
@Repository
public interface PlaceRepository extends JpaRepository<Place, Long> {
@Query(findPlace)
Place findBylattitudeAndlongitute(@Param("latitude") String latitude ,@Param("longitute") String longitute );
}
I am developing application based in spring jpa so I defined all the jpa configuration(entity manager , transaction etc) in configuration class.
Help me to resolve the above issue.