PostGIS几何保存:“遇到无效的尾数标记值”。 [英] PostGIS Geometry saving: "Invalid endian flag value encountered."

查看:387
本文介绍了PostGIS几何保存:“遇到无效的尾数标记值”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Roo + Hibernate项目,它从客户端应用程序获取JTS知名文本(WKT)字符串输入,将其转换为JTS几何对象,然后尝试将其写入PostGIS数据库。我在 JDBC连接和类型,但是这些似乎已经解决了:

$ p $ @Column(columnDefinition =Geometry,nullable = true)
私人几何centerPoint;

而转换的确如此:

<$ p $几何geom = new WKTReader(new GeometryFactory(new PrecisionModel(),4326))。read(source);

然而,现在当Hibernate尝试将我的Geometry对象写入数据库时​​,出现错误: p>

  2012-08-31 21:44:14406 [tomcat-http  -  18] ERROR org.hibernate.util.JDBCExceptionReporter  -  Batch入口0插入到land_use(center_point,version,id)值('< 1152字节的流>','0','1')被中止。调用getNextException来查看原因。 
2012-08-31 21:44:14,096 [tomcat-http - 18]错误org.hibernate.util.JDBCExceptionReporter - 错误:遇到无效的endian标志值。

似乎很清楚,错误与二进制表示有关, (WKB)和一些排序。然而,随着Hibernate隐藏所有的持久性,我无法确定事情进行的方式。



关于这些错误的信息很少,所以有没有人有任何明智的想法?我可以在何处指定字节序(Hibernate或PostGIS),或者以不同的格式(WKT)存储?

编辑:我也应该提到我正在使用最新的一切,它们通常看起来是兼容的:


  • Spring 3.1.1,Roo 1.2.1

  • hibernate 3.6.9

  • hibernate-spatial 4.0-M1

  • jts 1.12

  • PostgreSQL 9.1

  • postgis-jdbc 1.5.3(不是最新的,但是推荐用于hibernate-spatial ,从源代码编译)
  • postgis-jdbc 2.0.1(现在就试试这个来匹配PostgreSQL安装的版本,同样的问题)



Hibernate Spatial 4 tutorial 建议我做属性注释为:

  @Type(type = org.hibernate.spatia l.GeometryType)
private几何centerPoint;

...但是当我这样做时,我得到这个其他错误,这是当前注释解决的问题。


@Column 将字段映射到使用JPA注释

@Type 所需的列来指定Hibernate映射与方言。

  @Column(columnDefinition =Geometry,nullable = true)
@Type(type =org.hibernate.spatial.GeometryType)
公共点中心点;

您可以在hibernate.cfg.xml文件中添加Hibernate属性来查看数据库请求并尝试使用UTF-8/ANSI/其他字符集之类的基于文本的编辑器(如Notepad ++)来捕获字符串编码问题

 <! -  hibernate.cfg.xml  - > 
< property name =show_sql> true< / property>
< property name =format_sql> true< / property>
< property name =use_sql_comments> true< / property>

要添加hibernate属性,您将拥有一个包含以下内容的hibernate.cfg.xml文件。不要复制/粘贴它,因为它是面向MySQL的。

 <?xml version =1.0encoding =utf- 8\" >?; 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0 .dtd>
< hibernate-configuration>
< session-factory>
< property name =hibernate.bytecode.use_reflection_optimizer> true< / property>
< property name =hibernate.connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =hibernate.connection.password> db-password< / property>
< property name =hibernate.connection.url> jdbc:mysql:// localhost:3306 / db-name< / property>
< property name =hibernate.connection.username> db-username< / property>
< property name =hibernate.default_entity_mode> pojo< / property>
< property name =hibernate.dialect> org.hibernate.dialect.MySQL5InnoDBDialect< / property>
< property name =hibernate.format_sql> true< / property>
< property name =hibernate.search.autoregister_listeners> false< / property>
**< property name =hibernate.show_sql> true< / property> **
< property name =hibernate.use_sql_comments> false< / property>

< mapping ressource =..../>
<! - 下面的其他hbm.xml映射... - >

< / session-factory>
< / hibernate-configuration>

记录所有sql的另一种方法是在log4j.properties文件中添加特定于包的特性:

  log4j.logger.org.hibernate.SQL = DEBUG 
log4j.logger.org.hibernate.type = TRACE

祝您好运!


I have a Spring Roo + Hibernate project which takes a JTS well-known text (WKT) String input from the client application, converts it into a JTS Geometry object, and then attempts to write it to the PostGIS database. I had some problems with the JDBC connection and types, but these seem to have been resolved with:

@Column(columnDefinition = "Geometry", nullable = true) 
private Geometry centerPoint;

And the conversion does:

Geometry geom = new WKTReader(new GeometryFactory(new PrecisionModel(), 4326)).read(source);

However now when Hibernate tries to write my Geometry object to the database, I get an error:

2012-08-31 21:44:14,096 [tomcat-http--18] ERROR org.hibernate.util.JDBCExceptionReporter - Batch entry 0 insert into land_use (center_point, version, id) values ('<stream of 1152 bytes>', '0', '1') was aborted.  Call getNextException to see the cause.
2012-08-31 21:44:14,096 [tomcat-http--18] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: Invalid endian flag value encountered.

It seems clear that the error is related to the binary representation, which is presumably generated as a well-known binary (WKB) with some endianness. However with Hibernate hiding all the persistence away, I can't really tell which way things are going.

I've been fighting this Geometry stuff for days, and there's very little information out there on these error, so does anyone have any bright ideas? Can I specify the endianness somewhere (Hibernate or PostGIS), or perhaps store in a different format (WKT)?

EDIT: I should also mention that I'm using the newest of everything, which generally seems to be compatible:

  • Spring 3.1.1, Roo 1.2.1
  • hibernate 3.6.9
  • hibernate-spatial 4.0-M1
  • jts 1.12
  • PostgreSQL 9.1
  • postgis-jdbc 1.5.3 (not the latest, but recommended for hibernate-spatial, compiled from source)
  • postgis-jdbc 2.0.1 (just tried this now to match the version installed with PostgreSQL, same problem)

The Hibernate Spatial 4 tutorial suggests I do the property annotation as:

@Type(type="org.hibernate.spatial.GeometryType")
private Geometry centerPoint;

... but when I do this I get this other error, which the current annotation resolves.

解决方案

The solution seems to be the following:
@Column to map the field to the desired column with JPA annotations
@Type to specify the Hibernate mapping with the dialect.

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

You could add the Hibernate property inside the hibernate.cfg.xml file to see the db request and try to catch the string-encoded problem with a text based editor like Notepad++ with "UTF-8"/"ANSI"/"other charsets"

<!--hibernate.cfg.xml -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>

To add the hibernate properties you will have an hibernate.cfg.xml file with the following stuff. Don't copy/paste it because it is MySQL oriented. Just look where I have inserted the properties I evocated previously.

 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 <hibernate-configuration>
      <session-factory>
           <property name="hibernate.bytecode.use_reflection_optimizer">true</property>
           <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
           <property name="hibernate.connection.password">db-password</property>
           <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db-name</property>
           <property name="hibernate.connection.username">db-username</property>
           <property name="hibernate.default_entity_mode">pojo</property>
           <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
           <property name="hibernate.format_sql">true</property>
           <property name="hibernate.search.autoregister_listeners">false</property>
           **<property name="hibernate.show_sql">true</property>**
           <property name="hibernate.use_sql_comments">false</property>

           <mapping ressource="...." />
           <!-- other hbm.xml mappings below... -->

      </session-factory>
 </hibernate-configuration>

Another way to log all sql is to add package specific properties inside a log4j.properties file:

log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE

Good luck!

这篇关于PostGIS几何保存:“遇到无效的尾数标记值”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆