2

("b_shp")タイプ「geometry」の PostgreSQL 列をバインドしたいと考えています。特に、次のクエリは「POLYGON」の結果を返します。

SELECT GeometryType(b_shp)   ==>  "POLYGON"

@Column "b_shp"@Entity に適切な注釈が見つかりません。

私はこれらの注釈を試しました:

@Column(name="b_shp", columnDefinition="geometry(MultiPolygon,4326)")   
private com.vividsolutions.jts.geom.MultiPolygon b_shp;

と:

@Column(name="b_shp", columnDefinition="geometry")  
private com.vividsolutions.jts.geom.Geometry b_shp;

このエラーの取得:

ERROR:
javax.ejb.EJBException: java.lang.IllegalStateException: Received object of type org.postgresql.util.PGobject

私は使用しています:

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.0.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-spatial</artifactId>
            <version>5.0.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1205-jdbc42</version>
        </dependency>

        <dependency>
            <groupId>org.postgis</groupId>
            <artifactId>postgis-jdbc</artifactId>
            <version>1.3.3</version>
        </dependency>

正しい注釈は何ですか?

4

1 に答える 1

1

これはあなたの注釈の問題ではないと思います。同じエラーが発生しましたが、ワイルドフライによって提供されたデータソースを使用せず、代わりに次のようにデータベースに接続することで解決できました(persistence.xml):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="org.hibernate.events.jpa" transaction-type="JTA">
   <properties>
       <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
       <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
       <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/yourdatabase"/>
       <property name="hibernate.connection.username" value="username"/>
       <property name="hibernate.connection.password" value="password"/>
       <property name="hibernate.connection.pool_size" value="5"/>

       <property name="hibernate.show_sql" value="false"/>
       <property name="hibernate.format_sql" value="true"/>

       <property name="hibernate.max_fetch_depth" value="5"/>

       <property name="hibernate.hbm2ddl.auto" value="update"/>
   </properties>
</persistence-unit>

また、初期の 5.0.x バージョンの hibernate には明らかに hibernate-spatial が適切に統合されていないため、クラスパスの問題を回避するために、jboss-deployment-structure.xml ファイルを META-INF に追加しました。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
         <exclusions>
            <module name="org.hibernate" />
            <module name="org.postgresql" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

これにより、wildfly が提供する hibernate がデプロイで使用されなくなり、代わりに最新の hibernate バージョン (この記事の執筆時点では 5.1.0) の依存関係を追加できます。次に、hibernate、hibernate-spatial、および postgresql-jdbc の依存関係を追加する必要があります。

また、hibernate 5 では @Type アノテーションが不要になったことにも注意してください。

上記の設定と、次の属性/列を備えたエンティティの 1 つでプロジェクトを機能させることができました。

@Column(columnDefinition = "geometry(Point,4326)")
private Point position;

お役に立てば幸いです、頑張ってください!

編集:

wf10/hibernate5/postgis の使用を示す実用的なサンプル プロジェクトを用意しました。github で確認してください。

https://github.com/Pulvertoastmann/wf10postgis/

于 2016-03-23T13:31:29.750 に答える