Wrong Behaviour in HQL and SpatialFunction

2 messages Options
Embed this post
Permalink
Rafael Soto-2

Wrong Behaviour in HQL and SpatialFunction

Reply Threaded More More options
Print post
Permalink
Hi Folks,

Am writing a spatial query in hibernate spatial use HQL sintax.
My query uses a polymorphic feature and a SQL result has a wrong behaviour.
To improve a knowledge about the problem following are the details

{{{

BASE CLASS

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "GEOMETRY_TYPE", discriminatorType = DiscriminatorType.STRING)
public abstract class BaseClass {


  private Long id;


  ... get/set ...

 
    @Transient
    public abstract Geometry getGeo();
    public abstract void setGeo(Geometry geo);

}

LINE CLASS

@DiscriminatorValue("LINE")
public class LineClass extends BaseClass {


  private Geometry geo;

  @Override
  @Type(type = "org.hibernatespatial.GeometryUserType")
  @Column(name = "THE_GEOM_LINE", columnDefinition = "GEOMETRY")
    public Geometry getGeo() {
        return geo;
    }

    public void setGeo(Geometry geo) {
        this.geo = geo;
    }

 
}


Polygon CLASS

@DiscriminatorValue("POLYGON")
public class PolygonClass extends BaseClass {


  private Geometry geo;

  @Override
  @Type(type = "org.hibernatespatial.GeometryUserType")
  @Column(name = "THE_GEOM_POLYGON", columnDefinition = "GEOMETRY")
    public Geometry getGeo() {
        return geo;
    }

    public void setGeo(Geometry geo) {
        this.geo = geo;
    }

 
}

HQL QUERY

from BaseClass where within(geo,:externalFeature) = TRUE

SQL GENERATED QUERY

select baseclass0_.ID as ID18_, baseclass0_.THE_GEOM_LINE as THE9_18_, baseclass0_.THE_GEOM_POLYGON as THE10_18_, baseclass0_.GEOMETRY_TYPE as TYPE1_18_ from TABLE_EXAMPLE  baseclass0_ where intersects(baseclass0_.THE_GEOM_POLYGON, ?) = true

SQL EXPECTED QUERY

select baseclass0_.ID as ID18_, baseclass0_.THE_GEOM_LINE as THE9_18_, baseclass0_.THE_GEOM_POLYGON as THE10_18_, baseclass0_.GEOMETRY_TYPE as TYPE1_18_ from TABLE_EXAMPLE  baseclass0_ where intersects(baseclass0_.THE_GEOM_POLYGON, ?) = true AND intersects(baseclass0_.THE_GEOM_LINE, ?) = true


The correct query would be applied in all geometric attributes of the child classes a spatial function.

Everyone had this problem?

--
RAFAEL Almeida Fernandez Soto :: [hidden email]
Consultant in Java Enterprise Edition
Consultant in FOSS GIS :: 55 21 2518-6233 :: 55 71 8802-0600
OpenGEO :: On-demand training and solutions :: www.opengeo.com.br
GEO Livre community:: Because Geoinformation should be free :: www.geolivre.org.br
Be free by using Free Software, such as MapServer, PostgreSQL/PostGIS, gvSIG...
Linux User Number: 493334 :: http://counter.li.org/cgi-bin/certificate.cgi/493334


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

Re: Wrong Behaviour in HQL and SpatialFunction

Reply Threaded More More options
Print post
Permalink
Hello Rafael,

I think the SQL you expect would never return any results. A row  
represents either a LineClass or a PolygonClass object. In the first  
case, POLYGON_GEOMETRY is null, in the second LINE_GEOMETRY is null.  
So in all cases the WHERE condition evaluates to false.

I think the proper way to do this is to put the GEOMETRY column into  
the base class (i.e. make it shared by both subclasses): create a  
Geometry getter/setter in BaseClass and map it to a column GEOM (lets  
say)  in the table. This property is then inherited by LineClass and  
PolygonClass.

Btw, the resolution of property names to database columns is done by  
Hibernate. It is not something under the control of Hibernate Spatial.

Regards,

Karel

On 13 Sep 2009, at 16:59, Rafael Soto wrote:

> Hi Folks,
>
> Am writing a spatial query in hibernate spatial use HQL sintax.
> My query uses a polymorphic feature and a SQL result has a wrong  
> behaviour.
> To improve a knowledge about the problem following are the details
>
> {{{
>
> BASE CLASS
>
> @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
> @DiscriminatorColumn(name = "GEOMETRY_TYPE", discriminatorType =  
> DiscriminatorType.STRING)
> public abstract class BaseClass {
>
>
>   private Long id;
>
>
>   ... get/set ...
>
>
>     @Transient
>     public abstract Geometry getGeo();
>     public abstract void setGeo(Geometry geo);
>
> }
>
> LINE CLASS
>
> @DiscriminatorValue("LINE")
> public class LineClass extends BaseClass {
>
>
>   private Geometry geo;
>
>   @Override
>   @Type(type = "org.hibernatespatial.GeometryUserType")
>   @Column(name = "THE_GEOM_LINE", columnDefinition = "GEOMETRY")
>     public Geometry getGeo() {
>         return geo;
>     }
>
>     public void setGeo(Geometry geo) {
>         this.geo = geo;
>     }
>
>
> }
>
>
> Polygon CLASS
>
> @DiscriminatorValue("POLYGON")
> public class PolygonClass extends BaseClass {
>
>
>   private Geometry geo;
>
>   @Override
>   @Type(type = "org.hibernatespatial.GeometryUserType")
>   @Column(name = "THE_GEOM_POLYGON", columnDefinition = "GEOMETRY")
>     public Geometry getGeo() {
>         return geo;
>     }
>
>     public void setGeo(Geometry geo) {
>         this.geo = geo;
>     }
>
>
> }
>
> HQL QUERY
>
> from BaseClass where within(geo,:externalFeature) = TRUE
>
> SQL GENERATED QUERY
>
> select baseclass0_.ID as ID18_, baseclass0_.THE_GEOM_LINE as  
> THE9_18_, baseclass0_.THE_GEOM_POLYGON as THE10_18_,  
> baseclass0_.GEOMETRY_TYPE as TYPE1_18_ from TABLE_EXAMPLE  
> baseclass0_ where intersects(baseclass0_.THE_GEOM_POLYGON, ?) = true
>
> SQL EXPECTED QUERY
>
> select baseclass0_.ID as ID18_, baseclass0_.THE_GEOM_LINE as  
> THE9_18_, baseclass0_.THE_GEOM_POLYGON as THE10_18_,  
> baseclass0_.GEOMETRY_TYPE as TYPE1_18_ from TABLE_EXAMPLE  
> baseclass0_ where intersects(baseclass0_.THE_GEOM_POLYGON, ?) =  
> true AND intersects(baseclass0_.THE_GEOM_LINE, ?) = true
>
>
> The correct query would be applied in all geometric attributes of  
> the child classes a spatial function.
>
> Everyone had this problem?
>
> --
> RAFAEL Almeida Fernandez Soto :: [hidden email]
> Consultant in Java Enterprise Edition
> Consultant in FOSS GIS :: 55 21 2518-6233 :: 55 71 8802-0600
> OpenGEO :: On-demand training and solutions :: www.opengeo.com.br
> GEO Livre community:: Because Geoinformation should be free ::  
> www.geolivre.org.br
> Be free by using Free Software, such as MapServer, PostgreSQL/
> PostGIS, gvSIG...
> Linux User Number: 493334 :: http://counter.li.org/cgi-bin/ 
> certificate.cgi/493334
>
> _______________________________________________
> 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