I am working on a Java EE a have and entity project 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 out these places with a central point, if they are in a circle with a diameter of 1 km.

I need a method that only returns locations A, B, C, E.
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 examples, but I have to iterate over all locations on db (this will really be worth it)
Is it possible to do this directly using createQuery() ?
Note. I am using MySQL
source share