Quantcast

Hibernate Spatial fails to persist JTS Point

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Hibernate Spatial fails to persist JTS Point

Oliver Lade
Dear Hibernate Spatial Users,

I am at my wits' end having fought spatial persistence errors for over a week now. I have a question on Stack Overflow that describes my current (and hopefully final) problem in some detail.

In essence, I'm using Spring Roo with Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1 (via both the included 1.5.3 and compiled 2.0.1 JDBCs). I have a single entity, with a single Point attribute:


@Column(columnDefinition = "Geometry", nullable = true) 
@Type(type = "org.hibernate.spatial.GeometryType")
public Point centerPoint;

The HS4 Tutorial leaves out the @Column annotation, but if I do so I get errors about endianness. With it, I can at least submit a request to create a new object, however I then get an error that appears to be caused by my org.hibernate.spatial.dialect.postgis.PostgisDialect not being mapped correctly:


org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
...
Caused by: javax.persistence.RollbackException: Error while committing the transaction
at org
.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
    at org
.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
   
... 54 more
Caused by: java.lang.UnsupportedOperationException
    at org
.hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
    at org
.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
    at org
.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
    at org
.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
    at org
.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
    at org
.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
    at org
.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
    at org
.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
    at org
.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    at org
.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
    at org
.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
    at org
.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org
.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org
.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at org
.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    at org
.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
    at org
.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
   
... 55 more

I believe that I have everything set up correctly, but I've been staring at it for so long now that I don't even know. Does anybody know what might cause that error? You would truly be a lifesaver.

Regards,
Oliver

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Spatial fails to persist JTS Point

Karel Maesen
Administrator
Hi Oliver,

If you get this error, then the Hibernate Spatial dialect has not been loaded, and didn't get a change to overwrite the "generic" GeometrySqlTypeDescriptor with the Postgis-specific one. What version of Hibernate are you using?

I don't know much about Spring Roo, but sometimes Spring is set-up in such a way that dialect configuration settings are simply ignored. Spring then chooses a Dialect based on the JDBC connection-info, bypassing any configuration. Make sure you see in the logging somewhere that Hibernate is actually using the SpatialDialect.

Regards,

Karel


On 02 Sep 2012, at 18:25, Oliver Lade wrote:

> Dear Hibernate Spatial Users,
>
> I am at my wits' end having fought spatial persistence errors for over a week now. I have a question on Stack Overflow that describes my current (and hopefully final) problem in some detail.
>
> In essence, I'm using Spring Roo with Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1 (via both the included 1.5.3 and compiled 2.0.1 JDBCs). I have a single entity, with a single Point attribute:
>
>
> @Column(columnDefinition = "Geometry", nullable = true)
>
>
>
> @Type(type = "org.hibernate.spatial.GeometryType")
>
>
>
> public Point centerPoint;
>
> The HS4 Tutorial leaves out the @Column annotation, but if I do so I get errors about endianness. With it, I can at least submit a request to create a new object, however I then get an error that appears to be caused by my org.hibernate.spatial.dialect.postgis.PostgisDialect not being mapped correctly:
>
>
> org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
>
>
>
> ...
>
>
>
> Caused by: javax.persistence.RollbackException: Error while committing the transaction
>
>
> at org
> .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
>
>
>     at org
> .springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
>
>
>    
> ... 54 more
>
>
>
> Caused by: java.lang.UnsupportedOperationException
>
>
>     at org
> .hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
>
>
>     at org
> .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
>
>
>     at org
> .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
>
>
>     at org
> .hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
>
>
>     at org
> .hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
>
>
>     at org
> .hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
>
>
>     at org
> .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
>
>
>     at org
> .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
>
>
>     at org
> .hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
>
>
>     at org
> .hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
>
>
>     at org
> .hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
>
>
>     at org
> .hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
>
>
>     at org
> .hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
>
>
>     at org
> .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
>
>
>    
> ... 55 more
>
> I believe that I have everything set up correctly, but I've been staring at it for so long now that I don't even know. Does anybody know what might cause that error? You would truly be a lifesaver.
>
> Regards,
> Oliver
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Spatial fails to persist JTS Point

Oliver Lade
Hi Karel,

I was using the default Hibernate 3.6.9.Final (core and entitymanager), but amazingly as soon as I changed those to version 4.1.6.Final it... gave me a different error. But it looks a lot more manageable! So thank you! It's at least picking up the PostgisDialect, as I can see in the logs.

The new exception is below:

2012-09-04 19:37:31,847 [tomcat-http--6] DEBUG org.hibernate.internal.util.EntityPrinter - com.test.LandUse{id=7, centerPoint=POINT (1 4), version=0}
2012-09-04 19:37:31,857 [tomcat-http--6] DEBUG org.hibernate.SQL - 
    insert 
    into
        LandUse
        (centerPoint, version, id) 
    values
        (?, ?, ?)
Hibernate: 
    insert 
    into
        LandUse
        (centerPoint, version, id) 
    values
        (?, ?, ?)
2012-09-04 19:37:31,868 [tomcat-http--6] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column "center_point" is of type point but expression is of type geometry
  Hint: You will need to rewrite or cast the expression.
  Position: 56 [n/a]
org.postgresql.util.PSQLException: ERROR: column "center_point" is of type point but expression is of type geometry
  Hint: You will need to rewrite or cast the expression.
  Position: 56
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
...
2012-09-04 19:37:31,869 [tomcat-http--6] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42804
...

... and so on. It prints roughly the same error about ten times as it goes through the process of handling and rolling back and such, then eventually prints it to the error page. 

Does this look familiar? Do you know where I might look for the source?

Since the formatting appears to have messed up my previous message, my class is defined as:

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class LandUse {
@Column(columnDefinition="Point", nullable = true)
@Type(type = "org.hibernate.spatial.GeometryType")
private Point centerPoint;
}

Hibernate creates the table with:

Hibernate: 
    create table land_use (
        id int8 not null,
        center_point Point,
        version int4,
        primary key (id)
    )

Thank you very much again, and I hope this is the last problem I run into.

Kind regards,
Oliver

On 3 September 2012 03:10, Karel Maesen <[hidden email]> wrote:
Hi Oliver,

If you get this error, then the Hibernate Spatial dialect has not been loaded, and didn't get a change to overwrite the "generic" GeometrySqlTypeDescriptor with the Postgis-specific one. What version of Hibernate are you using?

I don't know much about Spring Roo, but sometimes Spring is set-up in such a way that dialect configuration settings are simply ignored. Spring then chooses a Dialect based on the JDBC connection-info, bypassing any configuration. Make sure you see in the logging somewhere that Hibernate is actually using the SpatialDialect.

Regards,

Karel


On 02 Sep 2012, at 18:25, Oliver Lade wrote:

> Dear Hibernate Spatial Users,
>
> I am at my wits' end having fought spatial persistence errors for over a week now. I have a question on Stack Overflow that describes my current (and hopefully final) problem in some detail.
>
> In essence, I'm using Spring Roo with Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1 (via both the included 1.5.3 and compiled 2.0.1 JDBCs). I have a single entity, with a single Point attribute:
>
>
> @Column(columnDefinition = "Geometry", nullable = true)
>
>
>
> @Type(type = "org.hibernate.spatial.GeometryType")
>
>
>
> public Point centerPoint;
>
> The HS4 Tutorial leaves out the @Column annotation, but if I do so I get errors about endianness. With it, I can at least submit a request to create a new object, however I then get an error that appears to be caused by my org.hibernate.spatial.dialect.postgis.PostgisDialect not being mapped correctly:
>
>
> org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
>
>
>
> ...
>
>
>
> Caused by: javax.persistence.RollbackException: Error while committing the transaction
>
>
> at org
> .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
>
>
>     at org
> .springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
>
>
>
> ... 54 more
>
>
>
> Caused by: java.lang.UnsupportedOperationException
>
>
>     at org
> .hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
>
>
>     at org
> .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
>
>
>     at org
> .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
>
>
>     at org
> .hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
>
>
>     at org
> .hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
>
>
>     at org
> .hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
>
>
>     at org
> .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
>
>
>     at org
> .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
>
>
>     at org
> .hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
>
>
>     at org
> .hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
>
>
>     at org
> .hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
>
>
>     at org
> .hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
>
>
>     at org
> .hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
>
>
>     at org
> .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
>
>
>
> ... 55 more
>
> I believe that I have everything set up correctly, but I've been staring at it for so long now that I don't even know. Does anybody know what might cause that error? You would truly be a lifesaver.
>
> Regards,
> Oliver
> _______________________________________________
> 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


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Spatial fails to persist JTS Point

Samuel Gendler
My only Roo project that uses Postgis has this for the @Type annotation - I assume the difference is because you are using a much more recent version of hibernate-spatial, but thought I'd throw it out there just in case:

    @Type(type = "org.hibernatespatial.GeometryUserType")




On Tue, Sep 4, 2012 at 3:00 AM, Oliver Lade <[hidden email]> wrote:
Hi Karel,

I was using the default Hibernate 3.6.9.Final (core and entitymanager), but amazingly as soon as I changed those to version 4.1.6.Final it... gave me a different error. But it looks a lot more manageable! So thank you! It's at least picking up the PostgisDialect, as I can see in the logs.

The new exception is below:

2012-09-04 19:37:31,847 [tomcat-http--6] DEBUG org.hibernate.internal.util.EntityPrinter - com.test.LandUse{id=7, centerPoint=POINT (1 4), version=0}
2012-09-04 19:37:31,857 [tomcat-http--6] DEBUG org.hibernate.SQL - 
    insert 
    into
        LandUse
        (centerPoint, version, id) 
    values
        (?, ?, ?)
Hibernate: 
    insert 
    into
        LandUse
        (centerPoint, version, id) 
    values
        (?, ?, ?)
2012-09-04 19:37:31,868 [tomcat-http--6] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column "center_point" is of type point but expression is of type geometry
  Hint: You will need to rewrite or cast the expression.
  Position: 56 [n/a]
org.postgresql.util.PSQLException: ERROR: column "center_point" is of type point but expression is of type geometry
  Hint: You will need to rewrite or cast the expression.
  Position: 56
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
...
2012-09-04 19:37:31,869 [tomcat-http--6] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42804
...

... and so on. It prints roughly the same error about ten times as it goes through the process of handling and rolling back and such, then eventually prints it to the error page. 

Does this look familiar? Do you know where I might look for the source?

Since the formatting appears to have messed up my previous message, my class is defined as:

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class LandUse {
@Column(columnDefinition="Point", nullable = true)
@Type(type = "org.hibernate.spatial.GeometryType")
private Point centerPoint;
}

Hibernate creates the table with:

Hibernate: 
    create table land_use (
        id int8 not null,
        center_point Point,
        version int4,
        primary key (id)
    )

Thank you very much again, and I hope this is the last problem I run into.

Kind regards,
Oliver

On 3 September 2012 03:10, Karel Maesen <[hidden email]> wrote:
Hi Oliver,

If you get this error, then the Hibernate Spatial dialect has not been loaded, and didn't get a change to overwrite the "generic" GeometrySqlTypeDescriptor with the Postgis-specific one. What version of Hibernate are you using?

I don't know much about Spring Roo, but sometimes Spring is set-up in such a way that dialect configuration settings are simply ignored. Spring then chooses a Dialect based on the JDBC connection-info, bypassing any configuration. Make sure you see in the logging somewhere that Hibernate is actually using the SpatialDialect.

Regards,

Karel


On 02 Sep 2012, at 18:25, Oliver Lade wrote:

> Dear Hibernate Spatial Users,
>
> I am at my wits' end having fought spatial persistence errors for over a week now. I have a question on Stack Overflow that describes my current (and hopefully final) problem in some detail.
>
> In essence, I'm using Spring Roo with Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1 (via both the included 1.5.3 and compiled 2.0.1 JDBCs). I have a single entity, with a single Point attribute:
>
>
> @Column(columnDefinition = "Geometry", nullable = true)
>
>
>
> @Type(type = "org.hibernate.spatial.GeometryType")
>
>
>
> public Point centerPoint;
>
> The HS4 Tutorial leaves out the @Column annotation, but if I do so I get errors about endianness. With it, I can at least submit a request to create a new object, however I then get an error that appears to be caused by my org.hibernate.spatial.dialect.postgis.PostgisDialect not being mapped correctly:
>
>
> org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
>
>
>
> ...
>
>
>
> Caused by: javax.persistence.RollbackException: Error while committing the transaction
>
>
> at org
> .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
>
>
>     at org
> .springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
>
>
>
> ... 54 more
>
>
>
> Caused by: java.lang.UnsupportedOperationException
>
>
>     at org
> .hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
>
>
>     at org
> .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
>
>
>     at org
> .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
>
>
>     at org
> .hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
>
>
>     at org
> .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
>
>
>     at org
> .hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
>
>
>     at org
> .hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
>
>
>     at org
> .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
>
>
>     at org
> .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
>
>
>     at org
> .hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
>
>
>     at org
> .hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
>
>
>     at org
> .hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
>
>
>     at org
> .hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
>
>
>     at org
> .hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
>
>
>     at org
> .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
>
>
>
> ... 55 more
>
> I believe that I have everything set up correctly, but I've been staring at it for so long now that I don't even know. Does anybody know what might cause that error? You would truly be a lifesaver.
>
> Regards,
> Oliver
> _______________________________________________
> 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


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Spatial fails to persist JTS Point

Karel Maesen
Administrator
I think I know what's going on here.

In Hibernate Spatial (at least up to now) you can only map something as a Geometry, and not as a more specific subtype of Geometry. In your case, Postgis is complaining when preparing a SQL statement that you're going to pass a Geometry into a Point column.

I guess that means that I should add all the more specific Geometry subtypes as Hibernate Types - that will require a bit of work.

In the mean time, a work-around is to change the database schema so your spatial columns are all defined to be of type Geometry (or Geography). In your Java class you can keep the type as Point (you can always insert a Point into a Geometry). You could also add to the table a check on the actual type being inserted to prevent anyone from inserting a linestring into the LandUse table.

Regards,

Karel Maesen
 


On 04 Sep 2012, at 17:48, Samuel Gendler wrote:

> My only Roo project that uses Postgis has this for the @Type annotation - I assume the difference is because you are using a much more recent version of hibernate-spatial, but thought I'd throw it out there just in case:
>
>     @Type(type = "org.hibernatespatial.GeometryUserType")
>
>
>
>
> On Tue, Sep 4, 2012 at 3:00 AM, Oliver Lade <[hidden email]> wrote:
> Hi Karel,
>
> I was using the default Hibernate 3.6.9.Final (core and entitymanager), but amazingly as soon as I changed those to version 4.1.6.Final it... gave me a different error. But it looks a lot more manageable! So thank you! It's at least picking up the PostgisDialect, as I can see in the logs.
>
> The new exception is below:
>
> 2012-09-04 19:37:31,847 [tomcat-http--6] DEBUG org.hibernate.internal.util.EntityPrinter - com.test.LandUse{id=7, centerPoint=POINT (1 4), version=0}
> 2012-09-04 19:37:31,857 [tomcat-http--6] DEBUG org.hibernate.SQL -
>     insert
>     into
>         LandUse
>         (centerPoint, version, id)
>     values
>         (?, ?, ?)
> Hibernate:
>     insert
>     into
>         LandUse
>         (centerPoint, version, id)
>     values
>         (?, ?, ?)
> 2012-09-04 19:37:31,868 [tomcat-http--6] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column "center_point" is of type point but expression is of type geometry
>   Hint: You will need to rewrite or cast the expression.
>   Position: 56 [n/a]
> org.postgresql.util.PSQLException: ERROR: column "center_point" is of type point but expression is of type geometry
>   Hint: You will need to rewrite or cast the expression.
>   Position: 56
> at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
> ...
> 2012-09-04 19:37:31,869 [tomcat-http--6] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42804
> ...
>
> ... and so on. It prints roughly the same error about ten times as it goes through the process of handling and rolling back and such, then eventually prints it to the error page.
>
> Does this look familiar? Do you know where I might look for the source?
>
> Since the formatting appears to have messed up my previous message, my class is defined as:
>
> @RooJavaBean
> @RooToString
> @RooJpaActiveRecord
> public class LandUse {
> @Column(columnDefinition="Point", nullable = true)
> @Type(type = "org.hibernate.spatial.GeometryType")
> private Point centerPoint;
> }
>
> Hibernate creates the table with:
>
> Hibernate:
>     create table land_use (
>         id int8 not null,
>         center_point Point,
>         version int4,
>         primary key (id)
>     )
>
> Thank you very much again, and I hope this is the last problem I run into.
>
> Kind regards,
> Oliver
>
> On 3 September 2012 03:10, Karel Maesen <[hidden email]> wrote:
> Hi Oliver,
>
> If you get this error, then the Hibernate Spatial dialect has not been loaded, and didn't get a change to overwrite the "generic" GeometrySqlTypeDescriptor with the Postgis-specific one. What version of Hibernate are you using?
>
> I don't know much about Spring Roo, but sometimes Spring is set-up in such a way that dialect configuration settings are simply ignored. Spring then chooses a Dialect based on the JDBC connection-info, bypassing any configuration. Make sure you see in the logging somewhere that Hibernate is actually using the SpatialDialect.
>
> Regards,
>
> Karel
>
>
> On 02 Sep 2012, at 18:25, Oliver Lade wrote:
>
> > Dear Hibernate Spatial Users,
> >
> > I am at my wits' end having fought spatial persistence errors for over a week now. I have a question on Stack Overflow that describes my current (and hopefully final) problem in some detail.
> >
> > In essence, I'm using Spring Roo with Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1 (via both the included 1.5.3 and compiled 2.0.1 JDBCs). I have a single entity, with a single Point attribute:
> >
> >
> > @Column(columnDefinition = "Geometry", nullable = true)
> >
> >
> >
> > @Type(type = "org.hibernate.spatial.GeometryType")
> >
> >
> >
> > public Point centerPoint;
> >
> > The HS4 Tutorial leaves out the @Column annotation, but if I do so I get errors about endianness. With it, I can at least submit a request to create a new object, however I then get an error that appears to be caused by my org.hibernate.spatial.dialect.postgis.PostgisDialect not being mapped correctly:
> >
> >
> > org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
> >
> >
> >
> > ...
> >
> >
> >
> > Caused by: javax.persistence.RollbackException: Error while committing the transaction
> >
> >
> > at org
> > .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
> >
> >
> >     at org
> > .springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
> >
> >
> >
> > ... 54 more
> >
> >
> >
> > Caused by: java.lang.UnsupportedOperationException
> >
> >
> >     at org
> > .hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
> >
> >
> >     at org
> > .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
> >
> >
> >     at org
> > .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
> >
> >
> >     at org
> > .hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
> >
> >
> >     at org
> > .hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
> >
> >
> >     at org
> > .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
> >
> >
> >     at org
> > .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
> >
> >
> >     at org
> > .hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
> >
> >
> >     at org
> > .hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
> >
> >
> >     at org
> > .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
> >
> >
> >     at org
> > .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
> >
> >
> >     at org
> > .hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
> >
> >
> >     at org
> > .hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
> >
> >
> >     at org
> > .hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
> >
> >
> >     at org
> > .hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
> >
> >
> >     at org
> > .hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
> >
> >
> >     at org
> > .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
> >
> >
> >
> > ... 55 more
> >
> > I believe that I have everything set up correctly, but I've been staring at it for so long now that I don't even know. Does anybody know what might cause that error? You would truly be a lifesaver.
> >
> > Regards,
> > Oliver
> > _______________________________________________
> > 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
>
>
> _______________________________________________
> 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

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate Spatial fails to persist JTS Point

Oliver Lade
Hi Karel,

I thought it might be something like that, though I'm too tired to piece these things together. It makes sense though, and I'm unbelievably happy to report that changing the columnDefinition to Geometry resolves the problem. I can enter a WKT string in the GUI, have Spring's controller convert it to a Point, then Hibernate takes the Point (as a Geometry) and converts it to a WKB string to store as a geometry type in the database. It's beautiful! It's also an acceptable workaround, since as you say, so long as Java knows it's a Point, the casting happens automatically. For the record, my (working!) property is now defined as:

@Column(columnDefinition="Geometry", nullable = true)
@Type(type = "org.hibernate.spatial.GeometryType")
private Point centerPoint;

And Sam, that's right; as far as I can tell, Hibernate Spatial 1.0 used @Type(type = "org.hibernatespatial.GeometryUserType") whereas Hibernate Spatial 4.0 now uses @Type(type="org.hibernate.spatial.GeometryType"). The two are otherwise equivalent.

Thank you so much again; it's time to write some actual code!

Regards,
Oliver

On 5 September 2012 02:01, Karel Maesen <[hidden email]> wrote:
I think I know what's going on here.

In Hibernate Spatial (at least up to now) you can only map something as a Geometry, and not as a more specific subtype of Geometry. In your case, Postgis is complaining when preparing a SQL statement that you're going to pass a Geometry into a Point column.

I guess that means that I should add all the more specific Geometry subtypes as Hibernate Types - that will require a bit of work.

In the mean time, a work-around is to change the database schema so your spatial columns are all defined to be of type Geometry (or Geography). In your Java class you can keep the type as Point (you can always insert a Point into a Geometry). You could also add to the table a check on the actual type being inserted to prevent anyone from inserting a linestring into the LandUse table.

Regards,

Karel Maesen



On 04 Sep 2012, at 17:48, Samuel Gendler wrote:

> My only Roo project that uses Postgis has this for the @Type annotation - I assume the difference is because you are using a much more recent version of hibernate-spatial, but thought I'd throw it out there just in case:
>
>     @Type(type = "org.hibernatespatial.GeometryUserType")
>
>
>
>
> On Tue, Sep 4, 2012 at 3:00 AM, Oliver Lade <[hidden email]> wrote:
> Hi Karel,
>
> I was using the default Hibernate 3.6.9.Final (core and entitymanager), but amazingly as soon as I changed those to version 4.1.6.Final it... gave me a different error. But it looks a lot more manageable! So thank you! It's at least picking up the PostgisDialect, as I can see in the logs.
>
> The new exception is below:
>
> 2012-09-04 19:37:31,847 [tomcat-http--6] DEBUG org.hibernate.internal.util.EntityPrinter - com.test.LandUse{id=7, centerPoint=POINT (1 4), version=0}
> 2012-09-04 19:37:31,857 [tomcat-http--6] DEBUG org.hibernate.SQL -
>     insert
>     into
>         LandUse
>         (centerPoint, version, id)
>     values
>         (?, ?, ?)
> Hibernate:
>     insert
>     into
>         LandUse
>         (centerPoint, version, id)
>     values
>         (?, ?, ?)
> 2012-09-04 19:37:31,868 [tomcat-http--6] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column "center_point" is of type point but expression is of type geometry
>   Hint: You will need to rewrite or cast the expression.
>   Position: 56 [n/a]
> org.postgresql.util.PSQLException: ERROR: column "center_point" is of type point but expression is of type geometry
>   Hint: You will need to rewrite or cast the expression.
>   Position: 56
>       at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
> ...
> 2012-09-04 19:37:31,869 [tomcat-http--6] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42804
> ...
>
> ... and so on. It prints roughly the same error about ten times as it goes through the process of handling and rolling back and such, then eventually prints it to the error page.
>
> Does this look familiar? Do you know where I might look for the source?
>
> Since the formatting appears to have messed up my previous message, my class is defined as:
>
> @RooJavaBean
> @RooToString
> @RooJpaActiveRecord
> public class LandUse {
>       @Column(columnDefinition="Point", nullable = true)
>       @Type(type = "org.hibernate.spatial.GeometryType")
>       private Point centerPoint;
> }
>
> Hibernate creates the table with:
>
> Hibernate:
>     create table land_use (
>         id int8 not null,
>         center_point Point,
>         version int4,
>         primary key (id)
>     )
>
> Thank you very much again, and I hope this is the last problem I run into.
>
> Kind regards,
> Oliver
>
> On 3 September 2012 03:10, Karel Maesen <[hidden email]> wrote:
> Hi Oliver,
>
> If you get this error, then the Hibernate Spatial dialect has not been loaded, and didn't get a change to overwrite the "generic" GeometrySqlTypeDescriptor with the Postgis-specific one. What version of Hibernate are you using?
>
> I don't know much about Spring Roo, but sometimes Spring is set-up in such a way that dialect configuration settings are simply ignored. Spring then chooses a Dialect based on the JDBC connection-info, bypassing any configuration. Make sure you see in the logging somewhere that Hibernate is actually using the SpatialDialect.
>
> Regards,
>
> Karel
>
>
> On 02 Sep 2012, at 18:25, Oliver Lade wrote:
>
> > Dear Hibernate Spatial Users,
> >
> > I am at my wits' end having fought spatial persistence errors for over a week now. I have a question on Stack Overflow that describes my current (and hopefully final) problem in some detail.
> >
> > In essence, I'm using Spring Roo with Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1 (via both the included 1.5.3 and compiled 2.0.1 JDBCs). I have a single entity, with a single Point attribute:
> >
> >
> > @Column(columnDefinition = "Geometry", nullable = true)
> >
> >
> >
> > @Type(type = "org.hibernate.spatial.GeometryType")
> >
> >
> >
> > public Point centerPoint;
> >
> > The HS4 Tutorial leaves out the @Column annotation, but if I do so I get errors about endianness. With it, I can at least submit a request to create a new object, however I then get an error that appears to be caused by my org.hibernate.spatial.dialect.postgis.PostgisDialect not being mapped correctly:
> >
> >
> > org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
> >
> >
> >
> > ...
> >
> >
> >
> > Caused by: javax.persistence.RollbackException: Error while committing the transaction
> >
> >
> > at org
> > .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
> >
> >
> >     at org
> > .springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
> >
> >
> >
> > ... 54 more
> >
> >
> >
> > Caused by: java.lang.UnsupportedOperationException
> >
> >
> >     at org
> > .hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
> >
> >
> >     at org
> > .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
> >
> >
> >     at org
> > .hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
> >
> >
> >     at org
> > .hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
> >
> >
> >     at org
> > .hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
> >
> >
> >     at org
> > .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
> >
> >
> >     at org
> > .hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
> >
> >
> >     at org
> > .hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
> >
> >
> >     at org
> > .hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
> >
> >
> >     at org
> > .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
> >
> >
> >     at org
> > .hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
> >
> >
> >     at org
> > .hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
> >
> >
> >     at org
> > .hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
> >
> >
> >     at org
> > .hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
> >
> >
> >     at org
> > .hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
> >
> >
> >     at org
> > .hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
> >
> >
> >     at org
> > .hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
> >
> >
> >
> > ... 55 more
> >
> > I believe that I have everything set up correctly, but I've been staring at it for so long now that I don't even know. Does anybody know what might cause that error? You would truly be a lifesaver.
> >
> > Regards,
> > Oliver
> > _______________________________________________
> > 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
>
>
> _______________________________________________
> 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

_______________________________________________
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
Loading...