I came across the following snipped in a Spring sample:
public interface StoreRepository extends PagingAndSortingRepository<Store, UUID> {
@RestResource(rel = "by-location")
Page<Store> findByAddressLocationNear(//
@Param("location") Point location, @Param("distance") Distance distance, Pageable pageable);}
I want to achieve a similar thing with my entities Shop and Address:
@Entity
public class Shop {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Getter @Setter
private long id;
@Getter @Setter
private String title;
@Getter @Setter
private String description;
@OneToMany(mappedBy = "shop")
@Getter @Setter
private List<Discount> discounts;
@OneToOne
@Getter @Setter
private Address address;
}
@Entity
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Getter @Setter
private long id;
@Getter @Setter
private Point location;
@Getter @Setter
private String street;
@Getter @Setter
private String city;
@Getter @Setter
private String zip;
}
How would the spring data repository query method look like to find Shops near a given location?
I tried List<Shop> findByAddressLocationNear(Point address_location, Distance d); but this doesn't work. I assume that I need either the Near or Within keyword.