OpenLiberty + Hibernate 空间 + Postgis 问题

问题描述 投票:0回答:1

我尝试将几何图形写入与 OpenLiberty 24.0.0.11 和 Hibernate-spatial 6.6.3.Final 一起启用的 Postgis 扩展的 Postgres 数据库,但出现以下错误:

jakarta.transaction.TransactionalException
[INFO]  at com.ibm.tx.jta.cdi.interceptors.TransactionalInterceptor.processException(TransactionalInterceptor.java:246)
...
 Caused by: org.hibernate.exception.SQLGrammarException: Unable to bind parameter #5 - SRID=4326;POINT(52.76751 5.048089) [Can't infer the SQL type to use for an instance of org.postgresql.util.PGobject. Use setObject() with an explicit Types value to specify the type to use.] [n/a]
[INFO]  at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:91)
[INFO]  at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:58)
[INFO]  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
[INFO]  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:94)
[INFO]  at org.hibernate.engine.jdbc.mutation.internal.JdbcValueBindingsImpl.lambda$beforeStatement$0(JdbcValueBindingsImpl.java:95)
[INFO]  at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[INFO]  at org.hibernate.engine.jdbc.mutation.spi.BindingGroup.forEachBinding(BindingGroup.java:51)
[INFO]  at org.hibernate.engine.jdbc.mutation.internal.JdbcValueBindingsImpl.beforeStatement(JdbcValueBindingsImpl.java:85)
[INFO]  at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecutor.java:130)
[INFO]  at org.hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:55)
[INFO]  at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:55)
[INFO]  at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.doStaticInserts(InsertCoordinatorStandard.java:194)
[INFO]  at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.coordinateInsert(InsertCoordinatorStandard.java:132)
[INFO]  at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.insert(InsertCoordinatorStandard.java:104)
[INFO]  at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:110)
[INFO]  at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:644)
[INFO]  at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:511)
[INFO]  at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:414)
[INFO]  at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
[INFO]  at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
[INFO]  at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1429)
[INFO]  at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:491)
[INFO]  at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2354)
[INFO]  at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1978)
[INFO]  at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
[INFO]  at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:336)
[INFO]  at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
[INFO]  at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
[INFO]  at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:239)
[INFO]  at com.ibm.tx.jta.impl.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:147)
[INFO]  at com.ibm.tx.jta.impl.TransactionImpl.prePrepare(TransactionImpl.java:1448)
[INFO]  at com.ibm.tx.jta.impl.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:862)
[INFO]  at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:818)
[INFO]  ... 73 more
[INFO] Caused by: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgresql.util.PGobject. Use setObject() with an explicit Types value to specify the type to use.
[INFO]  at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1064)
[INFO]  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
[INFO]  at java.base/java.lang.reflect.Method.invoke(Method.java:580)
[INFO]  at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:447)
[INFO]  at jdk.proxy11/jdk.proxy11.$Proxy228.setObject(Unknown Source)
[INFO]  at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setObject(WSJdbcPreparedStatement.java:1687)
[INFO]  at org.hibernate.spatial.dialect.postgis.AbstractPostGISJdbcType$1.doBind(AbstractPostGISJdbcType.java:104)
[INFO]  at org.hibernate.type.descriptor.jdbc.BasicBinder.bind(BasicBinder.java:61)
[INFO]  at org.hibernate.engine.jdbc.mutation.internal.JdbcValueBindingsImpl.lambda$beforeStatement$0(JdbcValueBindingsImpl.java:87)
[INFO]  ... 101 more
[INFO] 

不知何故它无法转换正确的几何类型。创建表可以与 Hibernate 配合使用(创建几何类型的列)。

我的server.xml如下:

<server description="${project.name}">

    <config monitorInterval="10s" />

    
    <variable name="postgres_user" defaultValue="drive" />
    <variable name="postgres_password" defaultValue="password" />
    <variable name="postgres_host" defaultValue="localhost" />
    <!--<variable name="postgress_port" defaultValue="5432"/> : not working (not a number but a string)-->


    <include location="keycloak.xml" optional="true" />
    <include location="dev.xml" optional="true" onConflict="REPLACE" />

    <!--  use jar: instead of wsjar: so e.g. EMFPlugin can find it resources -->
    <classloading useJarUrls="true" />


    <featureManager>

        <feature>appSecurity-5.0</feature>
        <feature>jsonb-3.0</feature>
<!--        <feature>beanValidation-3.0</feature>-->
        <feature>cdi-4.0</feature>
        <feature>restfulWS-3.1</feature> <!-- <feature>jaxrs-2.1</feature> -->
        <feature>mpConfig-3.1</feature>
        <feature>mpHealth-4.0</feature>
        <feature>mpJwt-2.1</feature>
        <feature>mpMetrics-5.1</feature>
        <feature>mpOpenAPI-3.1</feature>
        <feature>openIDConnectClient-1.0</feature>

        <!-- next few are for geographical persistance -->
        <feature>jdbc-4.3</feature>
        <!-- only use the JPA container code, not the default ORM provider (EclipseLink) as it does not support spatial queries -->
        <feature>persistenceContainer-3.1</feature> 
        <feature>bells-1.0</feature>

    </featureManager>
    
    <httpEndpoint id="defaultHttpEndpoint"
        host="*"
        httpPort="9080"
        httpsPort="9443"
         />

    <webApplication location="${project.name}.war" contextRoot="/">
        <!-- to directly reference hibernate APIs in the app, a shared library classloader is required, with same visibility-->
        <classloader apiTypeVisibility="+third-party" commonLibraryRef="hibernateLib" />
        
    </webApplication>

    <!-- database persistence -->
    <library id="jdbcLib" apiTypeVisibility="+third-party">
        <fileset dir="jdbc" includes="*.jar" />
    </library>

    <dataSource jndiName="jdbc/geometries">
        <jdbcDriver libraryRef="jdbcLib"   />
        <properties serverName="${postgres_host}" portNumber="5432"
            databaseName="esdl_geometries"
            user="${postgres_user}" password="${postgres_password}" />
    </dataSource>

    <library id="hibernateLib" apiTypeVisibility="+third-party">
        <fileset dir="${shared.resource.dir}/hibernate" includes="*.jar" />
    </library>

    <!-- register hibernate in the liberty runtime -->
    <!-- Making a 'bell' for the library will register any META-INF/services in the referenced library with the Liberty runtime -->
    <bell libraryRef="hibernateLib" />


</server>

休眠日志记录:

PersistenceUnitInfo [
[INFO]  name: jpa-unit
[INFO]  persistence provider classname: org.hibernate.jpa.HibernatePersistenceProvider
[INFO]  classloader: com.ibm.ws.classloading.internal.AppClassLoader@a1588c6
[INFO]  excludeUnlistedClasses: false
[INFO]  JTA datasource: com.ibm.ws.rsadapter.jdbc.v43.WSJdbc43DataSource@321d2feb
[INFO]  Non JTA datasource: null
[INFO]  Transaction type: JTA
[INFO]  PU root URL: file:/C:/data/git/esdl-drive/target/classes/
[INFO]  Shared Cache Mode: UNSPECIFIED
[INFO]  Validation Mode: null
[INFO]  Jar files URLs []
[INFO]  Managed classes names []
[INFO]  Mapping files names []
[INFO]  Properties [
[INFO]      hibernate.enhancer.enableDirtyTracking: false
[INFO]      hibernate.hbm2ddl.charset_name: UTF-8
[INFO]      hibernate.show_sql: true
[INFO]      hibernate.enhancer.enableLazyInitialization: false
[INFO]      hibernate.hbm2ddl.auto: create]
[INFO] [29-11-2024 11:39:46:246 CET] 0000005e SystemOut   O 880  [Default Executor-thread-18] DEBUG org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator  - Database ->
[INFO]     name : PostgreSQL
[INFO]  version : 12.8 (Debian 12.8-1.pgdg100+1)
[INFO]    major : 12
[INFO]    minor : 8
[INFO] [29-11-2024 11:39:46:247 CET] 0000005e SystemOut   O 881  [Default Executor-thread-18] DEBUG org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator  - Driver ->
[INFO]     name : PostgreSQL JDBC Driver
[INFO]  version : 42.7.4
[INFO]    major : 42
[INFO]    minor : 7
[INFO] [29-11-2024 11:39:46:247 CET] 0000005e SystemOut   O 881  [Default Executor-thread-18] DEBUG org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator  - JDBC version : 4.2
[INFO] [29-11-2024 11:39:46:297 CET] 0000005e SystemOut                                                    O 930  [Default Executor-thread-18] DEBUG org.hibernate.orm.dialect  - HHH035001: Using dialect: org.hibernate.dialect.PostgreSQLDialect, version: 12.8
[INFO] [29-11-2024 11:39:46:303 CET] 0000005e SystemOut    O 937  [Default Executor-thread-18] DEBUG org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder  - JDBC driver metadata reported database stores quoted identifiers in neither upper, lower nor mixed case
[INFO] [29-11-2024 11:39:46:319 CET] 0000005e SystemOut    O 953  [Default Executor-thread-18] DEBUG org.hibernate.orm.jdbc.lob  - HHH10010004: Disabling contextual LOB creation as Dialect reported it is not supported
[INFO] [29-11-2024 11:39:46:322 CET] 0000005e SystemOut    O 956  [Default Executor-thread-18] INFO  org.hibernate.orm.connections.pooling  - HHH10001005: Database info:
[INFO]  Database JDBC URL [Connecting through datasource 'com.ibm.ws.rsadapter.jdbc.v43.WSJdbc43DataSource@321d2feb']
[INFO]  Database driver: undefined/unknown
[INFO]  Database version: 12.8
[INFO]  Autocommit mode: undefined/unknown
[INFO]  Isolation level: undefined/unknown
[INFO]  Minimum pool size: undefined/unknown
[INFO]  Maximum pool size: undefined/unknown
[INFO] [29-11-2024 11:39:46:337 CET] 0000005e SystemOut                                                    O 971  [Default Executor-thread-18] INFO  org.hibernate.spatial  - HHH80000003: hibernate-spatial adding type contributions from : org.hibernate.spatial.dialect.postgis.PostgisDialectContributor
[INFO] [29-11-2024 11:39:46:479 CET] 0000005e SystemOut    O 1113 [Default Executor-thread-18] WARN  org.hibernate.orm.deprecation  - HHH90000029: The [hibernate.enhancer.enableLazyInitialization] configuration is deprecated and will be removed. Set the value to [true] to get rid of this warning
[INFO] [29-11-2024 11:39:46:480 CET] 0000005e SystemOut    O 1114 [Default Executor-thread-18] WARN  org.hibernate.orm.deprecation  - HHH90000029: The [hibernate.enhancer.enableDirtyTracking] configuration is deprecated and will be removed. Set the value to [true] to get rid of this warning
[INFO] [29-11-2024 11:39:46:480 CET] 0000005e SystemOut    O 1114 [Default Executor-thread-18] DEBUG org.hibernate.boot.internal.BootstrapContextImpl  - Injecting JPA temp ClassLoader [null] into BootstrapContext; was [com.ibm.ws.classloading.internal.ShadowClassLoader@14f72594]
[INFO] [29-11-2024 11:39:46:480 CET] 0000005e SystemOut    O 1114 [Default Executor-thread-18] DEBUG org.hibernate.boot.internal.ClassLoaderAccessImpl  - ClassLoaderAccessImpl#injectTempClassLoader(null) [was com.ibm.ws.classloading.internal.ShadowClassLoader@14f72594]
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.Geometry -> org.hibernate.spatial.GeolatteGeometryJavaType@77450d01 (was org.hibernate.spatial.GeolatteGeometryJavaType@77450d01)
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.Point -> org.hibernate.spatial.GeolatteGeometryJavaType@52d8c26a (was org.hibernate.spatial.GeolatteGeometryJavaType@52d8c26a)
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.LineString -> org.hibernate.spatial.GeolatteGeometryJavaType@61ad7310 (was org.hibernate.spatial.GeolatteGeometryJavaType@61ad7310)
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.Polygon -> org.hibernate.spatial.GeolatteGeometryJavaType@6a925e8c (was org.hibernate.spatial.GeolatteGeometryJavaType@6a925e8c)
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.MultiPoint -> org.hibernate.spatial.GeolatteGeometryJavaType@35e06bda (was org.hibernate.spatial.GeolatteGeometryJavaType@35e06bda)
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.MultiLineString -> org.hibernate.spatial.GeolatteGeometryJavaType@21bf249e (was org.hibernate.spatial.GeolatteGeometryJavaType@21bf249e)
[INFO] [29-11-2024 11:39:46:538 CET] 0000005e SystemOut   O 1172 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.MultiPolygon -> org.hibernate.spatial.GeolatteGeometryJavaType@2b80e64a (was org.hibernate.spatial.GeolatteGeometryJavaType@2b80e64a)
[INFO] [29-11-2024 11:39:46:539 CET] 0000005e SystemOut   O 1173 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.geolatte.geom.GeometryCollection -> org.hibernate.spatial.GeolatteGeometryJavaType@539ebb88 (was org.hibernate.spatial.GeolatteGeometryJavaType@539ebb88)
[INFO] [29-11-2024 11:39:46:539 CET] 0000005e SystemOut   O 1173 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.Geometry -> org.hibernate.spatial.JTSGeometryJavaType@6596b49a (was org.hibernate.spatial.JTSGeometryJavaType@6596b49a)
[INFO] [29-11-2024 11:39:46:539 CET] 0000005e SystemOut   O 1173 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.Point -> org.hibernate.spatial.JTSGeometryJavaType@3dd5e762 (was org.hibernate.spatial.JTSGeometryJavaType@3dd5e762)
[INFO] [29-11-2024 11:39:46:539 CET] 0000005e SystemOut   O 1173 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.LineString -> org.hibernate.spatial.JTSGeometryJavaType@114be424 (was org.hibernate.spatial.JTSGeometryJavaType@114be424)
[INFO] [29-11-2024 11:39:46:539 CET] 0000005e SystemOut   O 1173 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.Polygon -> org.hibernate.spatial.JTSGeometryJavaType@37af5f7e (was org.hibernate.spatial.JTSGeometryJavaType@37af5f7e)
[INFO] [29-11-2024 11:39:46:541 CET] 0000005e SystemOut   O 1174 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.MultiPoint -> org.hibernate.spatial.JTSGeometryJavaType@67cd1f75 (was org.hibernate.spatial.JTSGeometryJavaType@67cd1f75)
[INFO] [29-11-2024 11:39:46:541 CET] 0000005e SystemOut   O 1175 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.MultiLineString -> org.hibernate.spatial.JTSGeometryJavaType@75b11a19 (was org.hibernate.spatial.JTSGeometryJavaType@75b11a19)
[INFO] [29-11-2024 11:39:46:541 CET] 0000005e SystemOut   O 1175 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.MultiPolygon -> org.hibernate.spatial.JTSGeometryJavaType@3b95ba4f (was org.hibernate.spatial.JTSGeometryJavaType@3b95ba4f)
[INFO] [29-11-2024 11:39:46:541 CET] 0000005e SystemOut   O 1175 [Default Executor-thread-18] DEBUG org.hibernate.type.descriptor.java.spi.JavaTypeRegistry  - JavaTypeRegistry entry replaced : class org.locationtech.jts.geom.GeometryCollection -> org.hibernate.spatial.JTSGeometryJavaType@760c46ec (was org.hibernate.spatial.JTSGeometryJavaType@760c46ec)
[INFO] [29-11-2024 11:39:46:541 CET] 0000005e SystemOut   O 1175 [Default Executor-thread-18] INFO  org.hibernate.spatial  - HHH80000003: hibernate-spatial adding type contributions from : org.hibernate.spatial.dialect.postgis.PostgisDialectContributor

我可以看到几何类型已注册,但为什么它们没有被拾取? 我尝试正确配置类加载器(请参阅 server.xml),通过使用 liberty-maven-plugin 复制这些依赖项来确保 hibernate 在服务器中可用,但可能错过了一些东西?

谢谢!

postgresql jpa postgis open-liberty hibernate-spatial
1个回答
0
投票

我找到了解决方案:我必须将 postgresql 依赖范围从

runtime
更改为
provided
:

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>${postgresql.version}</version>
    <scope>provided</scope>
</dependency>

重读SO后,我根据这个SO答案尝试了这个https://stackoverflow.com/a/47819935/5210238和这个答案:Received object of type org.postgresql.util.PGobject

© www.soinside.com 2019 - 2024. All rights reserved.