I want to use Hibernate Spatial in Hibernate 3.6 HQL queries. I have the following domain class:
import com.vividsolutions.jts.geom.Point
class Book {
String title
Point location
static constraints = {
location nullable: true
}
}
I can make the following request:
def filter = reader.read('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))')
def session2 = sessionFactory.currentSession
def q = session2.createQuery("from Book b where within(location, ?) = true")
q.setParameter(0, filter, GeometryUserType.TYPE)
println (q.list())
The former works great. Now I want to write it something like this:
def queryParams = [:]
queryParams.loc = filter
List<Book> results = new ArrayList<>()
def query =
"""
select b from Book b
where within(b.location, :loc) = true
"""
results = Book.executeQuery(query, queryParams)
The problem with the last query is that the result is always empty.
How can I make the last request work?
source
share