HibernateSpatial MySql within query

3 messages Options
Embed this post
Permalink
dawez

HibernateSpatial MySql within query

Reply Threaded More More options
Print post
Permalink
Hi all,

I just started to use hubernatespatial few days ago and I am unable to make it work with a simple within query.

I am usign java topology suite (to create class with geometry features) and all is made in spring. I guess that there should no be differences from non-spring contained environment.

I will explain the problem i am facing:  This function should return a list of estates that are contained inside a specific polygon.

WKTReader fromText = new WKTReader();
String myArea = "POLYGON ((11 42, 13 42, 13 44, 13 42, 11 42))";
Geometry filter = null;
try {
   filter = fromText.read(myArea);
} catch (ParseException e) {
   throw new RuntimeException("Not a WKT String:" + myArea);
}
DetachedCriteria criteria = DetachedCriteria
        .forClass(Estate.class)
        .add(SpatialRestrictions.within("location", filter,filter));
return (List<Estate>) hibernateTemplate.findByCriteria(criteria);

The table estates has a column defined as Geometry.

the SQL command: select id,astext(location) from estates , reports:
ID - location
1 , POINT(11.538 42.872)
2 , POINT(10.917 42.883)
4 , POINT(11.083 42.883)
5 , POINT(10.917 42.883)

Which is correct. Btw when I try to execute the above Java code i got the following error

DEBUG SQL:401 - select this_.id as id0_0_, this_.location as location0_0_ from estates this_ where  within(this_.location,?)
WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: S1009
ERROR JDBCExceptionReporter:78 - Parameter index out of bounds. 2 is not between valid values of 1 and 1

Ok so now the big question, does anyone  know what is happening ?

regards,
Davide
Karel Maesen

Re: HibernateSpatial MySql within query

Reply Threaded More More options
Print post
Permalink
Hi David,


You can solve this by using

SpatialRestrictions.within("location", NULL, filter)

instead of

SpatialRestrictions.within("location", filter, filter)

The second parameter is for databases (such as Postgis) that can  
accept a separate filter geometry for a quick lookup in the spatial  
index. It is not used in the MySQL HS provider. I didn't realise it  
would return an error.

Regards,

Karel Maesen

       


On 31 Jan 2008, at 14:20, dawez wrote:

>
> Hi all,
>
> I just started to use hubernatespatial few days ago and I am unable  
> to make
> it work with a simple within query.
>
> I am usign java topology suite (to create class with geometry  
> features) and
> all is made in spring. I guess that there should no be differences  
> from
> non-spring contained environment.
>
> I will explain the problem i am facing:  This function should  
> return a list
> of estates that are contained inside a specific polygon.
>
> WKTReader fromText = new WKTReader();
> String myArea = "POLYGON ((11 42, 13 42, 13 44, 13 42, 11 42))";
> Geometry filter = null;
> try {
>    filter = fromText.read(myArea);
> } catch (ParseException e) {
>    throw new RuntimeException("Not a WKT String:" + myArea);
> }
> DetachedCriteria criteria = DetachedCriteria
>         .forClass(Estate.class)
>         .add(SpatialRestrictions.within("location", filter,filter));
> return (List<Estate>) hibernateTemplate.findByCriteria(criteria);
>
> The table estates has a column defined as Geometry.
>
> the SQL command: select id,astext(location) from estates , reports:
> ID - location
> 1 , POINT(11.538 42.872)
> 2 , POINT(10.917 42.883)
> 4 , POINT(11.083 42.883)
> 5 , POINT(10.917 42.883)
>
> Which is correct. Btw when I try to execute the above Java code i  
> got the
> following error
>
> DEBUG SQL:401 - select this_.id as id0_0_, this_.location as  
> location0_0_
> from estates this_ where  within(this_.location,?)
> WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: S1009
> ERROR JDBCExceptionReporter:78 - Parameter index out of bounds. 2  
> is not
> between valid values of 1 and 1
>
> Ok so now the big question, does anyone  know what is happening ?
>
> regards,
> Davide
> --
> View this message in context: http://www.nabble.com/ 
> HibernateSpatial-MySql-within-query-tp15204531p15204531.html
> Sent from the Hibernate Spatial - Users mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

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

Re: HibernateSpatial MySql within query

Reply Threaded More More options
Print post
Permalink
Hi Karel,

I applied  your solution and it worked perfectly ! :)

I have been struggling for quite long :)

Thank you again and keep working on such great extension !!!


Davide


Karel Maesen wrote:
Hi David,


You can solve this by using

SpatialRestrictions.within("location", NULL, filter)

instead of

SpatialRestrictions.within("location", filter, filter)

The second parameter is for databases (such as Postgis) that can  
accept a separate filter geometry for a quick lookup in the spatial  
index. It is not used in the MySQL HS provider. I didn't realise it  
would return an error.

Regards,

Karel Maesen

       


On 31 Jan 2008, at 14:20, dawez wrote:

>