복붙노트

[SPRING] PostGIS 기하 저장 중 : "잘못된 엔디안 플래그 값이 발생했습니다."

SPRING

PostGIS 기하 저장 중 : "잘못된 엔디안 플래그 값이 발생했습니다."

클라이언트 애플리케이션에서 JTS 잘 알려진 텍스트 (WKT) 문자열 입력을 받아 JTS Geometry 객체로 변환 한 다음 PostGIS 데이터베이스에 쓰려고 시도하는 Spring Roo + Hibernate 프로젝트가 있습니다. JDBC 연결 및 유형에 몇 가지 문제점이 있지만 다음과 같이 해결 된 것 같습니다.

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

그리고 변환은 :

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

그러나 지금 Hibernate가 데이터베이스에 내 Geometry 객체를 쓰려고 할 때 오류가 발생합니다 :

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.

오류가 바이너리 표현과 관련이있는 것으로 보입니다. 이진 표현은 아마도 일부 엔디안과 함께 잘 알려진 바이너리 (WKB)로 생성됩니다. 그러나 Hibernate가 모든 영속성을 숨기고 있기 때문에 나는 어떤 일이 진행되고 있는지를 정말로 알 수 없다.

며칠 동안이 기하학과 싸웠습니다.이 오류에 대한 정보는 거의 없으므로 누구나 밝은 아이디어가 있습니까? 엔디안 어딘가 (Hibernate 또는 PostGIS) 어딘가에 지정하거나 다른 형식 (WKT)으로 저장할 수 있습니까?

편집 : 나는 또한 일반적으로 호환되는 것 같다 모든 최신의 사용하고 언급해야합니다.

Hibernate Spatial 4 튜토리얼에서는 속성 주석을 다음과 같이 제안합니다.

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

...하지만이 작업을 수행 할 때 현재 주석이 해결하는 다른 오류가 발생합니다.

해결법

  1. ==============================

    1.해결책은 다음과 같다. JPA 주석으로 필드를 원하는 열로 매핑하는 @Column @Type은 방언으로 Hibernate 매핑을 지정한다.

    해결책은 다음과 같다. JPA 주석으로 필드를 원하는 열로 매핑하는 @Column @Type은 방언으로 Hibernate 매핑을 지정한다.

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

    Hibernate 속성을 hibernate.cfg.xml 파일에 추가하여 db 요청을보고 "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>
    

    Hibernate 프로퍼티를 추가하기 위해서 당신은 hibernate.cfg.xml 파일을 가지고있을 것입니다. MySQL 지향적이기 때문에 복사 / 붙여 넣기를하지 마십시오. 이전에 내가 상기 한 속성을 어디에 삽입했는지 살펴보십시오.

     <?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>
    

    모든 sql을 기록하는 또 다른 방법은 log4j.properties 파일 내에 패키지 특정 등록 정보를 추가하는 것입니다.

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

    행운을 빕니다!

  2. ==============================

    2.이 줄을 'application.properties'에 추가하면이 문제가 해결됩니다.

    이 줄을 'application.properties'에 추가하면이 문제가 해결됩니다.

    spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect
    
  3. ==============================

    3.http://trac.osgeo.org/postgis/ticket/1830도 참고하십시오. postgres 유틸리티 pgsql2shp를 사용할 때 "잘못된 엔디안 플래그"오류를 일으키는 Postgresql 9xx 및 Postgis 2xx가 나오는 시점에서 문제가 발생했습니다. Postgres가 bytea의 기본 동작을 변경했기 때문에 libpq.so 라이브러리의 이전 버전을 제거하는 문제를 해결할 수 있습니다.

    http://trac.osgeo.org/postgis/ticket/1830도 참고하십시오. postgres 유틸리티 pgsql2shp를 사용할 때 "잘못된 엔디안 플래그"오류를 일으키는 Postgresql 9xx 및 Postgis 2xx가 나오는 시점에서 문제가 발생했습니다. Postgres가 bytea의 기본 동작을 변경했기 때문에 libpq.so 라이브러리의 이전 버전을 제거하는 문제를 해결할 수 있습니다.

  4. from https://stackoverflow.com/questions/12215212/postgis-geometry-saving-invalid-endian-flag-value-encountered by cc-by-sa and MIT license