i have this entity
public class Shop implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String shop_name;
private String shop_street_address;
private String shop_zip;
private String shop_state;
private double SHOP_LATITUDE;
private double SHOP_LONGITUDE;
private double distance;
public Shop(String shop_name, String shop_street_address, String shop_zip, String shop_state, double SHOP_LATITUDE, double SHOP_LONGITUDE) {
this.shop_name = shop_name;
this.shop_street_address = shop_street_address;
this.shop_zip = shop_zip;
this.shop_state = shop_state;
this.SHOP_LATITUDE = SHOP_LATITUDE;
this.SHOP_LONGITUDE = SHOP_LONGITUDE;
}
public Shop() {
}
}
i also have this entity with getProximalShops statement that works just fine
@Repository
public interface ShopRepository extends CrudRepository<Shop, Integer> {
@Query(
value =
"SELECT *, " +
"( 3959 * acos ( cos ( radians(?1)) * cos( radians( SHOP_LATITUDE ) ) * cos( radians( SHOP_LONGITUDE ) - radians(?2) ) + sin ( radians(?1) ) * sin( radians( SHOP_LATITUDE )) ) ) " +
"AS DISTANCE FROM SHOP_INFORMATION GROUP BY ID HAVING DISTANCE < 2000 ORDER BY DISTANCE ASC LIMIT 0, 20",
nativeQuery = true)
List<Shop> getProximalShops(@Param("user_latitude") Double userlatitude,@Param("user_longitude") Double userlongitude);
}
List<Shop> getProximalShops(@Param("user_latitude") Double userlatitude,@Param("user_longitude") Double userlongitude);
this is my schema:
CREATE TABLE shop_information (
id INT AUTO_INCREMENT PRIMARY KEY,
shop_name VARCHAR(100) NOT NULL,
shop_street_address VARCHAR(100) NOT NULL,
shop_zip VARCHAR(10) NOT NULL,
shop_state VARCHAR(30) NOT NULL,
SHOP_LATITUDE DOUBLE NOT NULL,
SHOP_LONGITUDE DOUBLE NOT NULL
);
but when i try to do a regular findall(select * from jpa) it errors because it cant find distance in the table since its not available in the database, the only time distance is available is when calculated with the getProximalShops query and generated on the fly, i dont need to define it in my original schema.
is there a way to define it as optional preferably only set it when the db has that column? ive tried @transient but distance just doesn't get set when using getProximalShops but the findall(select * from jpa) statement works.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…