Problem inserting geometry into postgis

9 messages Options
Embed this post
Permalink
Suray Ph

Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Hello,

 

I am currently building a web application with gis functionalities.

In order to handle these ones, I use HibernateSpatial and Postgis. But I am running into an issue: when I insert a row with a geometry column, I got a ‘constrain violation’ from Postgis because my geometry has a different srid than the declared one stored in ‘geometry_columns’ table.

 

I have created my geometry column with ‘select addgeometrycolumn(…)’ statement. If I create the column with ‘create column …’ statement, the geometry is correctly inserted into the table (because no constrains were set on this column).

 

I think to the ‘insert’ statement generated by Hibernate is not correct, he does not use ‘st_geometryfromtext’ statement.

 

Could you confirm this behaviour? How can I correct this?

 

Thank you for your answer.

 

Suray Ph


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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
Hi Phillippe,

On 12 Dec 2007, at 18:10, Philippe Suray wrote:

> In order to handle these ones, I use HibernateSpatial and Postgis.  
> But I am running into an issue: when I insert a row with a geometry  
> column, I got a ‘constrain violation’ from Postgis because my  
> geometry has a different srid than the declared one stored in  
> ‘geometry_columns’ table.
>
> I have created my geometry column with ‘select addgeometrycolumn
> (…)’ statement. If I create the column with ‘create column …’  
> statement, the geometry is correctly inserted into the table  
> (because no constrains were set on this column).
>

That makes sense. The constraint violation is triggered by a check  
constaint on the geometry column that tests for a proper srid. This  
constraint is created by the "addgeometrycolumn". To resolve this you  
could either drop this particular constraint, which you seem to have  
done. Or by making sure that your geometries have the proper SRID by  
using a JTS geometry factory that creates geometries with that SRID,  
or by invoking setSRID on the geometry.

>  I think to the ‘insert’ statement generated by Hibernate is not  
> correct, he does not use ‘st_geometryfromtext’ statement.
>
> Could you confirm this behaviour? How can I correct this?
>

Hibernate Spatial doesn't use st_geometryfromtext, because it doesn't  
have to. The whole idea of Hibernate Spatial is to make it possible  
to just work with JTS Geometry objects. Hibernate Spatial ensures  
that these JTS Geometries are properly converted to whatever objects  
the database-specific JDBC driver expects for a prepared statement  
that stores geometries.

If this doesn't resolve the issue, or you still have questions, just  
let me know.

Regards,

Karel Maesen

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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
Hello Karel,

Thank you for your response. As you suggested, I've already dropped these
constrains in order to test.

I checked my code, the SRID is properly set on my geometry.

I've downloaded 'postgis' source and found an example using ejb3 and
Hibernate. In the GeometryType class, they use 'BinaryWriter' and
'BinaryParser' in 'nullSafeset' and 'nullSafeGet' method's.

Are you sure with the implementation of 'nullSafeSet' method?

Thank you for your response.

Suray Ph

-----Message d'origine-----
De : [hidden email]
[mailto:[hidden email]] De la
part de Karel Maesen
Envoyé : mercredi 12 décembre 2007 22:07
À : Hibernate Spatial Users Discussion
Objet : Re: [hibernatespatial-users] Problem inserting geometry into postgis

Hi Phillippe,

On 12 Dec 2007, at 18:10, Philippe Suray wrote:

> In order to handle these ones, I use HibernateSpatial and Postgis.  
> But I am running into an issue: when I insert a row with a geometry  
> column, I got a ‘constrain violation’ from Postgis because my  
> geometry has a different srid than the declared one stored in  
> ‘geometry_columns’ table.
>
> I have created my geometry column with ‘select addgeometrycolumn
> (…)’ statement. If I create the column with ‘create column …’  
> statement, the geometry is correctly inserted into the table  
> (because no constrains were set on this column).
>

That makes sense. The constraint violation is triggered by a check  
constaint on the geometry column that tests for a proper srid. This  
constraint is created by the "addgeometrycolumn". To resolve this you  
could either drop this particular constraint, which you seem to have  
done. Or by making sure that your geometries have the proper SRID by  
using a JTS geometry factory that creates geometries with that SRID,  
or by invoking setSRID on the geometry.

>  I think to the ‘insert’ statement generated by Hibernate is not  
> correct, he does not use ‘st_geometryfromtext’ statement.
>
> Could you confirm this behaviour? How can I correct this?
>

Hibernate Spatial doesn't use st_geometryfromtext, because it doesn't  
have to. The whole idea of Hibernate Spatial is to make it possible  
to just work with JTS Geometry objects. Hibernate Spatial ensures  
that these JTS Geometries are properly converted to whatever objects  
the database-specific JDBC driver expects for a prepared statement  
that stores geometries.

If this doesn't resolve the issue, or you still have questions, just  
let me know.

Regards,

Karel Maesen

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

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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
Hi Phillippe,

On 13 Dec 2007, at 09:29, Philippe Suray wrote:
> I've downloaded 'postgis' source and found an example using ejb3 and
> Hibernate. In the GeometryType class, they use 'BinaryWriter' and
> 'BinaryParser' in 'nullSafeset' and 'nullSafeGet' method's.
>
> Are you sure with the implementation of 'nullSafeSet' method?


Yes. Trust me, I know what I'm doing.

The code has been tested thoroughly, and I've used it successfully in  
several projects.

Regards,

Karel Maesen

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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
Hello Karel,

I checked my code and the DB, everything is OK now. The bug was on another
column and in the Hibernate criteria.

Apologize for disturbing the list.

Btw, do you plan to integrate a new Dialect for MsSqlSpatial in
HibernateSpatial? I am interested and could contribute if enough time.

Thank for your help and the great work.

Suray Ph
 

-----Message d'origine-----
De : [hidden email]
[mailto:[hidden email]] De la
part de Karel Maesen
Envoyé : jeudi 13 décembre 2007 19:19
À : Hibernate Spatial Users Discussion
Objet : Re: [hibernatespatial-users] Problem inserting geometry into postgis

Hi Phillippe,

On 13 Dec 2007, at 09:29, Philippe Suray wrote:
> I've downloaded 'postgis' source and found an example using ejb3 and
> Hibernate. In the GeometryType class, they use 'BinaryWriter' and
> 'BinaryParser' in 'nullSafeset' and 'nullSafeGet' method's.
>
> Are you sure with the implementation of 'nullSafeSet' method?


Yes. Trust me, I know what I'm doing.

The code has been tested thoroughly, and I've used it successfully in  
several projects.

Regards,

Karel Maesen

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

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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
> Btw, do you plan to integrate a new Dialect for MsSqlSpatial in
> HibernateSpatial? I am interested and could contribute if enough time.

Take a look at NHibernateSpatial project on codePlex.
http://www.codeplex.com/NHibernateSpatial
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
In reply to this post by Suray Ph
Hi Philippe,


On 14 Dec 2007, at 11:27, Philippe Suray wrote:

> I checked my code and the DB, everything is OK now. The bug was on  
> another
> column and in the Hibernate criteria.
>
> Apologize for disturbing the list.

No problem!

>
> Btw, do you plan to integrate a new Dialect for MsSqlSpatial in
> HibernateSpatial? I am interested and could contribute if enough time.

I'm always interested in adding new dialects. And every contribution  
is highly welcome?

I was thinking of supporting SQL Server 2008 native spatial types,  
rather than MsSqlSpatial.  You think MsSqlSpatial has a future after  
the release of MS SQL Server 2008.

Regards,

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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
Hello Karel,

I don't know if native spatial types will be included in Express edition, if
not i think it will be usefull to implements MsSqlSpatial extension.

Regards.

Philippe

-----Message d'origine-----
De : [hidden email]
[mailto:[hidden email]] De la
part de Karel Maesen
Envoyé : vendredi 14 décembre 2007 14:18
À : Hibernate Spatial Users Discussion
Objet : Re: [hibernatespatial-users] Problem inserting geometry into postgis

Hi Philippe,


On 14 Dec 2007, at 11:27, Philippe Suray wrote:

> I checked my code and the DB, everything is OK now. The bug was on  
> another
> column and in the Hibernate criteria.
>
> Apologize for disturbing the list.

No problem!

>
> Btw, do you plan to integrate a new Dialect for MsSqlSpatial in
> HibernateSpatial? I am interested and could contribute if enough time.

I'm always interested in adding new dialects. And every contribution  
is highly welcome?

I was thinking of supporting SQL Server 2008 native spatial types,  
rather than MsSqlSpatial.  You think MsSqlSpatial has a future after  
the release of MS SQL Server 2008.

Regards,

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

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

Re: Problem inserting geometry into postgis

Reply Threaded More More options
Print post
Permalink
OK. We'll see what the express edition brings.

I won't have time to work on this until at least february next year.  
If you decided to contribute, let me know. I can assist you to start  
writing a suitable provider.

Regards,

Karel Maesen


On 18 Dec 2007, at 18:07, Philippe Suray wrote:

> Hello Karel,
>
> I don't know if native spatial types will be included in Express  
> edition, if
> not i think it will be usefull to implements MsSqlSpatial extension.
>
> Regards.
>
> Philippe
>
> -----Message d'origine-----
> De : [hidden email]
> [mailto:[hidden email]]  
> De la
> part de Karel Maesen
> Envoyé : vendredi 14 décembre 2007 14:18
> À : Hibernate Spatial Users Discussion
> Objet : Re: [hibernatespatial-users] Problem inserting geometry  
> into postgis
>
> Hi Philippe,
>
>
> On 14 Dec 2007, at 11:27, Philippe Suray wrote:
>
>> I checked my code and the DB, everything is OK now. The bug was on
>> another
>> column and in the Hibernate criteria.
>>
>> Apologize for disturbing the list.
>
> No problem!
>
>>
>> Btw, do you plan to integrate a new Dialect for MsSqlSpatial in
>> HibernateSpatial? I am interested and could contribute if enough  
>> time.
>
> I'm always interested in adding new dialects. And every contribution
> is highly welcome?
>
> I was thinking of supporting SQL Server 2008 native spatial types,
> rather than MsSqlSpatial.  You think MsSqlSpatial has a future after
> the release of MS SQL Server 2008.
>
> Regards,
>
> Karel
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-us
> ers
>
> _______________________________________________
> 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