java.lang.ClassCastException: when trying to use JGeometry and Geometry class

10 messages Options
Embed this post
Permalink
aarthi.h

java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi,
I get a  java.lang.ClassCastException: oracle.spatial.geometry.JGeometry cannot be cast to com.vividsolutions.jts.geom.Geometry.

I am trying to query my oracle database which has a SDO_Geometry column.

private static final String HQL_FIND_NN = " Select gf from GeoFeature as gf where "
                        + " gf.geometry= :geom ";

Query query = getEntityManager().createQuery(HQL_FIND_NN);

                        //vividSolutions.jts.Geometry object.
                        Geometry geom = feature.getGeometry();
                       
                        //creating a JGeometry object to pass to the query
                        JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
                                        .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());

                        query.setParameter("geom", jGeom);
                       
                       
                        STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();



As variations, I tried not casting the query.getSingleResult() into a STRUCT, but to a Geometry or a JGeometry obj.
This class cast exception happens in the getSingleResult() method. So, I believe Hibernate spatial is trying to convert a JGeometry type to a Geometry object.

I also tried passing in the vividsolutions.jts.Geometry obejct for the 'geom' parameter too, but that gave me other exceptions saying incompatible types.

Can you please advice me on exactly how one can query the db and use the functions on the geometry column using hibernate spatial..? I think I am not doing something right here.


Version Info:
hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008


Thanks in advance.
Aarthi
Karel Maesen

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi Aarthi,


On 15 Feb 2008, at 01:16, aarthi.h wrote:

>                         //vividSolutions.jts.Geometry object.
> Geometry geom = feature.getGeometry();
>
>                         //creating a JGeometry object to pass to  
> the query
> JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
> .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());
>
> query.setParameter("geom", jGeom);
>
>
> STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();
>

Your example should be something like this:

Geometry geom = feature.getGeometry();
query.setParameter("geom", geom)
Geometry geom = (Geometry)query.getSingleResult();


> Version Info:
> hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
> hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>

I suggest you use the latest release 1.0-M1. This has some important  
improvements that might resolve your issues. Also with this release,  
you don't need the sdoapi.jar anymore (SDO_GEOMETRY objects are now  
internally converted to JTS Geometries).

If the problems persist, provide a complete stack trace so that I  
understand where exactly the problem arises.

Regards,

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

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi Karel,
Thank you for your reply. I updated to the latest code from svn checkout http://www.hibernatespatial.org/svn/ 
hibernate-spatial/trunk/hibernate-spatial hibernate-spatial trunk.

The latest revision seems to have been dont on 1/25/2008.

 Here's what I get now:

javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query

Caused by: java.sql.SQLException: ORA-22901: cannot compare nested table or VARRAY or LOB attributes of an object type

My code is :

private static final String HQL_FIND_NN = " Select gf from GeoFeature as gf where "
                        + " gf.geometry= :geom ";
Query query = getEntityManager().createQuery(HQL_FIND_NN);

                        Geometry geom = feature.getGeometry();

                        query.setParameter("geom", geom);
                        geom = (Geometry) query.getSingleResult();


The Geometry that I am passing is a point and all my data in the database are of type="Point". I have made sure my dimensions of the Geometry obj. match that in the db.
Can I not compare geometry like this? Should I be comparing the dimensions instead? If so, can you advice me on the sql I should be providing?

Thanks in advance,
Aarthi












Karel Maesen wrote:
Hi Aarthi,


On 15 Feb 2008, at 01:16, aarthi.h wrote:

>                         //vividSolutions.jts.Geometry object.
> Geometry geom = feature.getGeometry();
>
>                         //creating a JGeometry object to pass to  
> the query
> JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
> .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());
>
> query.setParameter("geom", jGeom);
>
>
> STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();
>

Your example should be something like this:

Geometry geom = feature.getGeometry();
query.setParameter("geom", geom)
Geometry geom = (Geometry)query.getSingleResult();


> Version Info:
> hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
> hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>

I suggest you use the latest release 1.0-M1. This has some important  
improvements that might resolve your issues. Also with this release,  
you don't need the sdoapi.jar anymore (SDO_GEOMETRY objects are now  
internally converted to JTS Geometries).

If the problems persist, provide a complete stack trace so that I  
understand where exactly the problem arises.

Regards,

Karel
_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@lists.hibernatespatial.org
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi,

I only now noticed that your query string is invalid because you  
cannot directly test two geometries for equality (at least not in  
Oracle). You must use of the defined OGC spatial functions such as  
"contains" or "within".

Regards,

Karel



On 15 Feb 2008, at 22:35, aarthi.h wrote:

>
> Hi Karel,
> Thank you for your reply. I updated to the latest code from svn  
> checkout
> http://www.hibernatespatial.org/svn/
> hibernate-spatial/trunk/hibernate-spatial hibernate-spatial trunk.
>
> The latest revision seems to have been dont on 1/25/2008.
>
>  Here's what I get now:
>
> javax.persistence.PersistenceException:
> org.hibernate.exception.GenericJDBCException: could not execute query
>
> Caused by: java.sql.SQLException: ORA-22901: cannot compare nested  
> table or
> VARRAY or LOB attributes of an object type
>
> My code is :
>
> private static final String HQL_FIND_NN = " Select gf from  
> GeoFeature as gf
> where "
> + " gf.geometry= :geom ";
> Query query = getEntityManager().createQuery(HQL_FIND_NN);
>
> Geometry geom = feature.getGeometry();
>
> query.setParameter("geom", geom);
> geom = (Geometry) query.getSingleResult();
>
> The Geometry that I am passing is a point and all my data in the  
> database
> are of type="Point". I have made sure my dimensions of the Geometry  
> obj.
> match that in the db.
> Can I not compare geometry like this? Should I be comparing the  
> dimensions
> instead? If so, can you advice me on the sql I should be providing?
>
> Thanks in advance,
> Aarthi
>
>
>
>
>
>
>
>
>
>
>
>
>
> Karel Maesen wrote:
>>
>> Hi Aarthi,
>>
>>
>> On 15 Feb 2008, at 01:16, aarthi.h wrote:
>>
>>>                         //vividSolutions.jts.Geometry object.
>>> Geometry geom = feature.getGeometry();
>>>
>>>                         //creating a JGeometry object to pass to
>>> the query
>>> JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
>>> .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());
>>>
>>> query.setParameter("geom", jGeom);
>>>
>>>
>>> STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();
>>>
>>
>> Your example should be something like this:
>>
>> Geometry geom = feature.getGeometry();
>> query.setParameter("geom", geom)
>> Geometry geom = (Geometry)query.getSingleResult();
>>
>>
>>> Version Info:
>>> hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>> hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>>
>>
>> I suggest you use the latest release 1.0-M1. This has some important
>> improvements that might resolve your issues. Also with this release,
>> you don't need the sdoapi.jar anymore (SDO_GEOMETRY objects are now
>> internally converted to JTS Geometries).
>>
>> If the problems persist, provide a complete stack trace so that I
>> understand where exactly the problem arises.
>>
>> Regards,
>>
>> Karel
>> _______________________________________________
>> hibernatespatial-users mailing list
>> [hidden email]
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
>> hibernatespatial-users
>>
>>
>
> --
> View this message in context: http://www.nabble.com/ 
> java.lang.ClassCastException%3A-when-trying-to-use-JGeometry-and-
> Geometry-class-tp15492414p15510573.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
aarthi.h

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi Karel,
Oops. I just realized my mistake the same time as your reply :).
I tried OGC functions like SDO_EQUAL , SDO_CONTAINS and SDO_RELATE.

Here's my query:
 Select gf from GeoFeature as gf where "
                        + " SDO_RELATE(gf.geometry, :geom, 'mask=equal') = 'TRUE'  


variations include :
 Select gf from GeoFeature as gf where "
                        + " SDO_EQUAL(gf.geometry, :geom) = 'TRUE'  


and  Select gf from GeoFeature as gf where "
                        + " SDO_CONTAINS(gf.geometry, :geom) = 'TRUE'


I always get the following errror:
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query

Caused by: java.sql.SQLException: ORA-29900: operator binding does not exist
ORA-06553: PLS-306: wrong number or types of arguments in call to 'SDO_RELATE'


As you would've guessed, I am completely new to oracle spatial. Any help is really appreciated.

Thank you.
Aarthi

Karel Maesen wrote:
Hi,

I only now noticed that your query string is invalid because you  
cannot directly test two geometries for equality (at least not in  
Oracle). You must use of the defined OGC spatial functions such as  
"contains" or "within".

Regards,

Karel



On 15 Feb 2008, at 22:35, aarthi.h wrote:

>
> Hi Karel,
> Thank you for your reply. I updated to the latest code from svn  
> checkout
> http://www.hibernatespatial.org/svn/
> hibernate-spatial/trunk/hibernate-spatial hibernate-spatial trunk.
>
> The latest revision seems to have been dont on 1/25/2008.
>
>  Here's what I get now:
>
> javax.persistence.PersistenceException:
> org.hibernate.exception.GenericJDBCException: could not execute query
>
> Caused by: java.sql.SQLException: ORA-22901: cannot compare nested  
> table or
> VARRAY or LOB attributes of an object type
>
> My code is :
>
> private static final String HQL_FIND_NN = " Select gf from  
> GeoFeature as gf
> where "
> + " gf.geometry= :geom ";
> Query query = getEntityManager().createQuery(HQL_FIND_NN);
>
> Geometry geom = feature.getGeometry();
>
> query.setParameter("geom", geom);
> geom = (Geometry) query.getSingleResult();
>
> The Geometry that I am passing is a point and all my data in the  
> database
> are of type="Point". I have made sure my dimensions of the Geometry  
> obj.
> match that in the db.
> Can I not compare geometry like this? Should I be comparing the  
> dimensions
> instead? If so, can you advice me on the sql I should be providing?
>
> Thanks in advance,
> Aarthi
>
>
>
>
>
>
>
>
>
>
>
>
>
> Karel Maesen wrote:
>>
>> Hi Aarthi,
>>
>>
>> On 15 Feb 2008, at 01:16, aarthi.h wrote:
>>
>>>                         //vividSolutions.jts.Geometry object.
>>> Geometry geom = feature.getGeometry();
>>>
>>>                         //creating a JGeometry object to pass to
>>> the query
>>> JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
>>> .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());
>>>
>>> query.setParameter("geom", jGeom);
>>>
>>>
>>> STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();
>>>
>>
>> Your example should be something like this:
>>
>> Geometry geom = feature.getGeometry();
>> query.setParameter("geom", geom)
>> Geometry geom = (Geometry)query.getSingleResult();
>>
>>
>>> Version Info:
>>> hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>> hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>>
>>
>> I suggest you use the latest release 1.0-M1. This has some important
>> improvements that might resolve your issues. Also with this release,
>> you don't need the sdoapi.jar anymore (SDO_GEOMETRY objects are now
>> internally converted to JTS Geometries).
>>
>> If the problems persist, provide a complete stack trace so that I
>> understand where exactly the problem arises.
>>
>> Regards,
>>
>> Karel
>> _______________________________________________
>> hibernatespatial-users mailing list
>> hibernatespatial-users@lists.hibernatespatial.org
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
>> hibernatespatial-users
>>
>>
>
> --
> View this message in context: http://www.nabble.com/ 
> java.lang.ClassCastException%3A-when-trying-to-use-JGeometry-and-
> Geometry-class-tp15492414p15510573.html
> Sent from the Hibernate Spatial - Users mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@lists.hibernatespatial.org
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@lists.hibernatespatial.org
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi,

In HQL you should use the special OGC functions that are defined by  
Hibernate Spatial. These are portable across different spatial  
databases (Mysql, postgis, oracle).

Correct examples are:

"select gf from GeoFeature where equals(gf.geometry, :geom)"
"select gf from GeoFeature where contains(:geom, gf.geometry)"
"select gf form GeoFeature where within(gf.geometry, :geom)"

These functions are defined in the OGC Simple Features for SQL  
Specification (see the specifcation on the site http://
www.opengeospatial.org).

Regards,

Karel



On 15 Feb 2008, at 23:44, aarthi.h wrote:

>
> Hi Karel,
> Oops. I just realized my mistake the same time as your reply :).
> I tried OGC functions like SDO_EQUAL , SDO_CONTAINS and SDO_RELATE.
>
> Here's my query:
>  Select gf from GeoFeature as gf where "
> + " SDO_RELATE(gf.geometry, :geom, 'mask=equal') = 'TRUE'
>
> variations include :
>  Select gf from GeoFeature as gf where "
> + " SDO_EQUAL(gf.geometry, :geom) = 'TRUE'
>
> and  Select gf from GeoFeature as gf where "
> + " SDO_CONTAINS(gf.geometry, :geom) = 'TRUE'
>
> I always get the following errror:
> javax.persistence.PersistenceException:
> org.hibernate.exception.GenericJDBCException: could not execute query
>
> Caused by: java.sql.SQLException: ORA-29900: operator binding does  
> not exist
> ORA-06553: PLS-306: wrong number or types of arguments in call to
> 'SDO_RELATE'
>
>
> As you would've guessed, I am completely new to oracle spatial. Any  
> help is
> really appreciated.
>
> Thank you.
> Aarthi
>
>
> Karel Maesen wrote:
>>
>> Hi,
>>
>> I only now noticed that your query string is invalid because you
>> cannot directly test two geometries for equality (at least not in
>> Oracle). You must use of the defined OGC spatial functions such as
>> "contains" or "within".
>>
>> Regards,
>>
>> Karel
>>
>>
>>
>> On 15 Feb 2008, at 22:35, aarthi.h wrote:
>>
>>>
>>> Hi Karel,
>>> Thank you for your reply. I updated to the latest code from svn
>>> checkout
>>> http://www.hibernatespatial.org/svn/
>>> hibernate-spatial/trunk/hibernate-spatial hibernate-spatial trunk.
>>>
>>> The latest revision seems to have been dont on 1/25/2008.
>>>
>>>  Here's what I get now:
>>>
>>> javax.persistence.PersistenceException:
>>> org.hibernate.exception.GenericJDBCException: could not execute  
>>> query
>>>
>>> Caused by: java.sql.SQLException: ORA-22901: cannot compare nested
>>> table or
>>> VARRAY or LOB attributes of an object type
>>>
>>> My code is :
>>>
>>> private static final String HQL_FIND_NN = " Select gf from
>>> GeoFeature as gf
>>> where "
>>> + " gf.geometry= :geom ";
>>> Query query = getEntityManager().createQuery(HQL_FIND_NN);
>>>
>>> Geometry geom = feature.getGeometry();
>>>
>>> query.setParameter("geom", geom);
>>> geom = (Geometry) query.getSingleResult();
>>>
>>> The Geometry that I am passing is a point and all my data in the
>>> database
>>> are of type="Point". I have made sure my dimensions of the Geometry
>>> obj.
>>> match that in the db.
>>> Can I not compare geometry like this? Should I be comparing the
>>> dimensions
>>> instead? If so, can you advice me on the sql I should be providing?
>>>
>>> Thanks in advance,
>>> Aarthi
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Karel Maesen wrote:
>>>>
>>>> Hi Aarthi,
>>>>
>>>>
>>>> On 15 Feb 2008, at 01:16, aarthi.h wrote:
>>>>
>>>>>                         //vividSolutions.jts.Geometry object.
>>>>> Geometry geom = feature.getGeometry();
>>>>>
>>>>>                         //creating a JGeometry object to pass to
>>>>> the query
>>>>> JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
>>>>> .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());
>>>>>
>>>>> query.setParameter("geom", jGeom);
>>>>>
>>>>>
>>>>> STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();
>>>>>
>>>>
>>>> Your example should be something like this:
>>>>
>>>> Geometry geom = feature.getGeometry();
>>>> query.setParameter("geom", geom)
>>>> Geometry geom = (Geometry)query.getSingleResult();
>>>>
>>>>
>>>>> Version Info:
>>>>> hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>>>> hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>>>>
>>>>
>>>> I suggest you use the latest release 1.0-M1. This has some  
>>>> important
>>>> improvements that might resolve your issues. Also with this  
>>>> release,
>>>> you don't need the sdoapi.jar anymore (SDO_GEOMETRY objects are now
>>>> internally converted to JTS Geometries).
>>>>
>>>> If the problems persist, provide a complete stack trace so that I
>>>> understand where exactly the problem arises.
>>>>
>>>> Regards,
>>>>
>>>> Karel
>>>> _______________________________________________
>>>> hibernatespatial-users mailing list
>>>> [hidden email]
>>>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
>>>> hibernatespatial-users
>>>>
>>>>
>>>
>>> --
>>> View this message in context: http://www.nabble.com/
>>> java.lang.ClassCastException%3A-when-trying-to-use-JGeometry-and-
>>> Geometry-class-tp15492414p15510573.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
>>
>>
>
> --
> View this message in context: http://www.nabble.com/ 
> java.lang.ClassCastException%3A-when-trying-to-use-JGeometry-and-
> Geometry-class-tp15492414p15511635.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
aarthi.h

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi Karel,
Thank you so much. I wasn't doing that right.

Here's my sql and code below.

private static final String HQL_FIND_NN = " Select gf from GeoFeature as gf where "
                        + " Equals(gf.geometry, ? )=true
 ";


                       org.hibernate.Query query = session.createQuery(HQL_FIND_NN);

                        com.vividsolutions.jts.geom.Geometry geom = feature.getGeometry();
                        Type geometryType = new CustomType(GeometryUserType.class, null);

                        query.setParameter(0, geom, geometryType);
                       
                       //geom= (Geometry) query.uniqueResult();

                        List list = query.list();

and I get this error:

org.hibernate.exception.SQLGrammarException: could not execute query


Caused by: java.sql.SQLException: ORA-06531: Reference to uninitialized collection
ORA-06512: at "MDSYS.ST_GEOMETRY", line 611
ORA-06512: at "MDSYS.OGC_EQUALS", line 6

My hibernate sql is:
 select
      <all the feature columns>
    from
        feature geofeature0_
    where
        MDSYS.OGC_EQUALS(MDSYS.ST_GEOMETRY.FROM_SDO_GEOM(geofeature0_.geometry),MDSYS.ST_GEOMETRY.FROM_SDO_GEOM(?))=1

When I try to run the same query in my SQL browser by substituting the ? with a custom geometry, it works.
What am I doing wrong here? Please advice. Thanks once again for your time on this issue.

Aarthi

PS: I am using oracle 10g.


Karel Maesen wrote:
Hi,

In HQL you should use the special OGC functions that are defined by  
Hibernate Spatial. These are portable across different spatial  
databases (Mysql, postgis, oracle).

Correct examples are:

"select gf from GeoFeature where equals(gf.geometry, :geom)"
"select gf from GeoFeature where contains(:geom, gf.geometry)"
"select gf form GeoFeature where within(gf.geometry, :geom)"

These functions are defined in the OGC Simple Features for SQL  
Specification (see the specifcation on the site http://
www.opengeospatial.org).

Regards,

Karel



On 15 Feb 2008, at 23:44, aarthi.h wrote:

>
> Hi Karel,
> Oops. I just realized my mistake the same time as your reply :).
> I tried OGC functions like SDO_EQUAL , SDO_CONTAINS and SDO_RELATE.
>
> Here's my query:
>  Select gf from GeoFeature as gf where "
> + " SDO_RELATE(gf.geometry, :geom, 'mask=equal') = 'TRUE'
>
> variations include :
>  Select gf from GeoFeature as gf where "
> + " SDO_EQUAL(gf.geometry, :geom) = 'TRUE'
>
> and  Select gf from GeoFeature as gf where "
> + " SDO_CONTAINS(gf.geometry, :geom) = 'TRUE'
>
> I always get the following errror:
> javax.persistence.PersistenceException:
> org.hibernate.exception.GenericJDBCException: could not execute query
>
> Caused by: java.sql.SQLException: ORA-29900: operator binding does  
> not exist
> ORA-06553: PLS-306: wrong number or types of arguments in call to
> 'SDO_RELATE'
>
>
> As you would've guessed, I am completely new to oracle spatial. Any  
> help is
> really appreciated.
>
> Thank you.
> Aarthi
>
>
> Karel Maesen wrote:
>>
>> Hi,
>>
>> I only now noticed that your query string is invalid because you
>> cannot directly test two geometries for equality (at least not in
>> Oracle). You must use of the defined OGC spatial functions such as
>> "contains" or "within".
>>
>> Regards,
>>
>> Karel
>>
>>
>>
>> On 15 Feb 2008, at 22:35, aarthi.h wrote:
>>
>>>
>>> Hi Karel,
>>> Thank you for your reply. I updated to the latest code from svn
>>> checkout
>>> http://www.hibernatespatial.org/svn/
>>> hibernate-spatial/trunk/hibernate-spatial hibernate-spatial trunk.
>>>
>>> The latest revision seems to have been dont on 1/25/2008.
>>>
>>>  Here's what I get now:
>>>
>>> javax.persistence.PersistenceException:
>>> org.hibernate.exception.GenericJDBCException: could not execute  
>>> query
>>>
>>> Caused by: java.sql.SQLException: ORA-22901: cannot compare nested
>>> table or
>>> VARRAY or LOB attributes of an object type
>>>
>>> My code is :
>>>
>>> private static final String HQL_FIND_NN = " Select gf from
>>> GeoFeature as gf
>>> where "
>>> + " gf.geometry= :geom ";
>>> Query query = getEntityManager().createQuery(HQL_FIND_NN);
>>>
>>> Geometry geom = feature.getGeometry();
>>>
>>> query.setParameter("geom", geom);
>>> geom = (Geometry) query.getSingleResult();
>>>
>>> The Geometry that I am passing is a point and all my data in the
>>> database
>>> are of type="Point". I have made sure my dimensions of the Geometry
>>> obj.
>>> match that in the db.
>>> Can I not compare geometry like this? Should I be comparing the
>>> dimensions
>>> instead? If so, can you advice me on the sql I should be providing?
>>>
>>> Thanks in advance,
>>> Aarthi
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Karel Maesen wrote:
>>>>
>>>> Hi Aarthi,
>>>>
>>>>
>>>> On 15 Feb 2008, at 01:16, aarthi.h wrote:
>>>>
>>>>>                         //vividSolutions.jts.Geometry object.
>>>>> Geometry geom = feature.getGeometry();
>>>>>
>>>>>                         //creating a JGeometry object to pass to
>>>>> the query
>>>>> JGeometry jGeom = new JGeometry(geom.getCoordinate().x, geom
>>>>> .getCoordinate().y, geom.getCoordinate().z, geom.getSRID());
>>>>>
>>>>> query.setParameter("geom", jGeom);
>>>>>
>>>>>
>>>>> STRUCT st = (oracle.sql.STRUCT) query.getSingleResult();
>>>>>
>>>>
>>>> Your example should be something like this:
>>>>
>>>> Geometry geom = feature.getGeometry();
>>>> query.setParameter("geom", geom)
>>>> Geometry geom = (Geometry)query.getSingleResult();
>>>>
>>>>
>>>>> Version Info:
>>>>> hibernate-spatial-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>>>> hibernate-spatial-oracle-1.0-SNAPSHOT.jar asofDate: 1/15/2008
>>>>>
>>>>
>>>> I suggest you use the latest release 1.0-M1. This has some  
>>>> important
>>>> improvements that might resolve your issues. Also with this  
>>>> release,
>>>> you don't need the sdoapi.jar anymore (SDO_GEOMETRY objects are now
>>>> internally converted to JTS Geometries).
>>>>
>>>> If the problems persist, provide a complete stack trace so that I
>>>> understand where exactly the problem arises.
>>>>
>>>> Regards,
>>>>
>>>> Karel
>>>> _______________________________________________
>>>> hibernatespatial-users mailing list
>>>> hibernatespatial-users@lists.hibernatespatial.org
>>>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
>>>> hibernatespatial-users
>>>>
>>>>
>>>
>>> --
>>> View this message in context: http://www.nabble.com/
>>> java.lang.ClassCastException%3A-when-trying-to-use-JGeometry-and-
>>> Geometry-class-tp15492414p15510573.html
>>> Sent from the Hibernate Spatial - Users mailing list archive at
>>> Nabble.com.
>>>
>>> _______________________________________________
>>> hibernatespatial-users mailing list
>>> hibernatespatial-users@lists.hibernatespatial.org
>>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
>>> hibernatespatial-users
>>
>> _______________________________________________
>> hibernatespatial-users mailing list
>> hibernatespatial-users@lists.hibernatespatial.org
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
>> hibernatespatial-users
>>
>>
>
> --
> View this message in context: http://www.nabble.com/ 
> java.lang.ClassCastException%3A-when-trying-to-use-JGeometry-and-
> Geometry-class-tp15492414p15511635.html
> Sent from the Hibernate Spatial - Users mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@lists.hibernatespatial.org
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@lists.hibernatespatial.org
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
This type of error usually arises from invalid, empty or null  
geometries. Could you verify that your table has non-null geometries  
and that the test geometry you pass is not null.

Regards,

  Karel

On 16 Feb 2008, at 01:38, aarthi.h wrote:

>
> and I get this error:
>
> org.hibernate.exception.SQLGrammarException: could not execute query
>
>
> Caused by: java.sql.SQLException: ORA-06531: Reference to  
> uninitialized
> collection
> ORA-06512: at "MDSYS.ST_GEOMETRY", line 611
> ORA-06512: at "MDSYS.OGC_EQUALS", line 6
>

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

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi Karel,
Thanks for the response. I apologize for the delay, I was out on vacation. I checked for null geometries and everything works fine now. :)

Another question, in oracle my geometry is a Point( which has a longitude, latitude and elevation). When I insert the data through java, I create a point as  

vividsolutions.jts.geom.Coordinate coordinate = new Coordinate(longitude, latitude, elevation);
vividsolutions.jts.geom.Point geom = new GeometryFactory().createPoint(coordinate);

i.e, longitude first then latitude. I don't see javadocs on the vividsolutions.jts Point class, hence this question :). (I am a total newbie to spatial).

Thanks so much for all the help.

Aarthi



Karel Maesen wrote:
This type of error usually arises from invalid, empty or null  
geometries. Could you verify that your table has non-null geometries  
and that the test geometry you pass is not null.

Regards,

  Karel

On 16 Feb 2008, at 01:38, aarthi.h wrote:
>
> and I get this error:
>
> org.hibernate.exception.SQLGrammarException: could not execute query
>
>
> Caused by: java.sql.SQLException: ORA-06531: Reference to  
> uninitialized
> collection
> ORA-06512: at "MDSYS.ST_GEOMETRY", line 611
> ORA-06512: at "MDSYS.OGC_EQUALS", line 6
>

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@lists.hibernatespatial.org
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
aarthi.h

Re: java.lang.ClassCastException: when trying to use JGeometry and Geometry class

Reply Threaded More More options
Print post
Permalink
Hi Karel,
Sorry for the really basic question. I double checked and things are fine for now.
Thanks once again for all the help. Great job!

Aarthi



aarthi.h wrote:
Hi Karel,
Thanks for the response. I apologize for the delay, I was out on vacation. I checked for null geometries and everything works fine now. :)

Another question, in oracle my geometry is a Point( which has a longitude, latitude and elevation). When I insert the data through java, I create a point as  

vividsolutions.jts.geom.Coordinate coordinate = new Coordinate(longitude, latitude, elevation);
vividsolutions.jts.geom.Point geom = new GeometryFactory().createPoint(coordinate);

i.e, longitude first then latitude. I don't see javadocs on the vividsolutions.jts Point class, hence this question :). (I am a total newbie to spatial).

Thanks so much for all the help.

Aarthi



Karel Maesen wrote:
This type of error usually arises from invalid, empty or null  
geometries. Could you verify that your table has non-null geometries  
and that the test geometry you pass is not null.

Regards,

  Karel

On 16 Feb 2008, at 01:38, aarthi.h wrote:
>
> and I get this error:
>
> org.hibernate.exception.SQLGrammarException: could not execute query
>
>
> Caused by: java.sql.SQLException: ORA-06531: Reference to  
> uninitialized
> collection
> ORA-06512: at "MDSYS.ST_GEOMETRY", line 611
> ORA-06512: at "MDSYS.OGC_EQUALS", line 6
>

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@lists.hibernatespatial.org
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users