Dear stackoverflow readers,
I'm currently working on an application that has the requirement to load specific items based on its coordinates. Example: I want all shops from coordinates x or within 15 km of it.
I have been building this web application in Java EE 6 and used Hibernate 3.3 for data persistence to my Postgres database. After some reseach I found Hibernate-Spatial as an possibility to achieve my goal. I installed Postgis and have Hibernate-Spatial running.
I'm using Hibernate 3.3, Hibernate-Spatial 1.0, PostgreSQL 9.2 and postgis-jdbc 1.3.3.
I created an entity which has a location field:
@Column(columnDefinition = "Geometry", nullable = true)
@Type(type = "org.hibernatespatial.GeometryUserType")
private Point location;
Initially I thought I could create a Circle and basically query on every point which is located in the circle. But this seems harder than I thought. So hard that I'm starting to think I made the wrong choice of using Hibernate-Spatial.
My question is if it's possible by using Hibernate-Spatial to query on every Point within a specific boundry (coordinates x and y km's from there).
I'm also interested in other possibilities to solve my requirement. I've been thinking about the following possibilities:
- Just use a Native query on PostgreSQL, map those results to entities and use those in the other parts of the application (Basically remove Hibernate-Spatial and use native queries).
- Switch to Hibernate-Search and use Lucene to fulfill my task.
- Something completely else
Can anyone please provide an example of how I can achieve my wish in Hibernate-Spatial or how I can achieve my requirement in another way.