I'm working on a Java EE project an have and entity like this:
@Entity
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long messageId;
@ManyToOne
private User user;
private String name;
private Float latitude;
private Float longitude;
}
And I need to filter these locations with a center point if they are in 1 km diameter circle.
I need a method like this returning only A, B, C, E locations.
public List<Location> findLocations(Float longitude, Float latitude) {
List<Location> locations =
entityManager.createQuery("select l from Location where ???")
.setParameter("longitude", longitude)
.setParameter("latitude", latitude)
.getResultList();
return locations;
}
I found some code samples, but I must iterate over all locations on db (this will be really costed)
Can I do it directly with createQuery()
?
Note: I'm using
MySQL