我想在Hibernate 3.6 HQL查询中使用Hibernate Spatial。我有以下域类:
import com.vividsolutions.jts.geom.Point
class Book {
String title
Point location
static constraints = {
location nullable: true
}
}
我可以进行以下查询:
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())
前者工作正常。现在我想写得更像这样:
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)
上次查询的问题是结果始终为空。
如何让最后一个查询生效?