HQL and functions (invalid geometry)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

HQL and functions (invalid geometry)

Daniel Henrique Alves Lima
   Hi.

   I'm sorry for my poor writing skills in English (my native language is Portuguese). I'm a HB and HBS newbie.
   I'm trying to understand why Query.list() fails for H (it does work for E, F and G). Isn't this related to Hibernate spatial at all? I'm
using HBS + PostGIS.

   Some context:
http://grails.1312388.n4.nabble.com/Grails-hibernate-custom-user-type-and-DomainClass-executeQuery-tp3761623p3762955.html

   I read http://hibernate-spatial.1140993.n2.nabble.com/Problems-with-executing-HQL-with-hibernate-spatial-td1141004.html#a1141005,
but I'm not sure why it works for E and it doesn't work for H. Is it related to functions usage?

   Thanks in advance.

   The code:

            Geometry filter = reader.read('POLYGON((1 1,20 1,20 20, 1 20, 1 1))')
            assert filter instanceof Geometry

           // E
            Query query = sessionFactory.currentSession.createQuery('from Organization where location = ?')
            query.setParameter(0, filter)
            orgs = query.list()
            println "E: orgs ${orgs}"

           // F
            query = sessionFactory.currentSession.createQuery('from Organization where within(?, location) = true')
            query.setParameter(0, filter, new org.hibernate.type.CustomType(org.hibernatespatial.GeometryUserType, null))
            orgs = query.list()
            println "F: orgs ${orgs}"

            // G
            Criteria criteria = Organization.createCriteria()
            criteria.add(SpatialRestrictions.within('location', filter))
            orgs = query.list()
            println "G: orgs ${orgs}"
           
            // H
            query = sessionFactory.currentSession.createQuery('from Organization where within(?, location) = true')
            query.setParameter(0, filter)
            orgs = query.list()
            println "H: orgs ${orgs}"


======
Log

2011-08-23 12:57:53,839 [main] DEBUG hibernate.SQL  - select organizati0_.id as id0_, organizati0_.location as location0_, organizati0_.name as name0_ from organization organizati0_ where organizati0_.location=?
E: orgs []
2011-08-23 12:57:53,855 [main] DEBUG hibernate.SQL  - select organizati0_.id as id0_, organizati0_.location as location0_, organizati0_.name as name0_ from organization organizati0_ where within(?, organizati0_.location)=true
F: orgs []
2011-08-23 12:57:53,876 [main] DEBUG hibernate.SQL  - select organizati0_.id as id0_, organizati0_.location as location0_, organizati0_.name as name0_ from organization organizati0_ where within(?, organizati0_.location)=true
G: orgs []
2011-08-23 12:57:53,877 [main] DEBUG hibernate.SQL  - select organizati0_.id as id0_, organizati0_.location as location0_, organizati0_.name as name0_ from organization organizati0_ where within(?, organizati0_.location)=true
2011-08-23 12:57:53,898 [main] TRACE type.SerializableType  - binding '2c6d(...)' to parameter: 1
2011-08-23 12:57:53,900 [main] ERROR util.JDBCExceptionReporter  - ERROR: parse error - invalid geometry
2011-08-23 12:57:53,917 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: could not execute query
org.hibernate.exception.GenericJDBCException: could not execute query
(...)
Caused by: org.postgresql.util.PSQLException: ERROR: parse error - invalid geometry
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
        ... 34 more


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users