本文介绍了Postgres错误方法org.postgresql.jdbc.PgConnection.createClob()未实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用连接对象调用createClob方法时,如下所示:

When I invoke createClob method using connection object as shown below:

Clob clob = con.createClob();

引发以下异常:

Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
        at org.postgresql.Driver.notImplemented(Driver.java:659)
        at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1246)
        at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868)
        at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868)

我使用带有JDK8的数据库PostgreSQL 9.6.2和commons-dbcp2连接池,并在pom.xml中添加了以下Postgres依赖项

I`m using database PostgreSQL 9.6.2 with JDK8 and using commons-dbcp2 connection pool, And added following Postgres dependency in pom.xml

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.1.1</version>
</dependency>

在类org.postgresql.jdbc.PgConnection中,createClob实现如下所示,该异常引发异常:

In class org.postgresql.jdbc.PgConnection, createClob implementation is as shown below which is throwing the exception:

@Override
public Clob createClob() throws SQLException {
    checkClosed();
    throw org.postgresql.Driver.notImplemented(this.getClass(), "createClob()");
}

解决此问题的解决方案或解决方法是什么?或者我们如何在 Postgres 查询中设置CLOB数据?

What is the solution or workaround to overcome this issue? Or How can we set CLOB data in Postgres queries?

推荐答案

TL; DR

  • application.yml中设置spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
  • persistence.xml
  • 中设置hibernate.jdbc.lob.non_contextual_creation=true
  • Set spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true in your application.yml or,
  • Set hibernate.jdbc.lob.non_contextual_creation=true in your persistence.xml

这是JBoss社区中的一个已知错误.

It's a known error in JBoss community.

此错误在Spring-Boot 2.0.0.RC1及更高版本的旧版本和新版本中都会出现.

This error appears in former versions and new version with Spring-Boot 2.0.0.RC1 as well and higher.

解决方案:

  1. 使用较新的向后兼容版本更新您的postgressql驱动程序.
    • application.yml中设置spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
    • 在persistence.xml中设置hibernate.jdbc.lob.non_contextual_creation=true
  1. Update your postgressql-driver with a newer backward compatible version.
    • Set spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true in your application.yml or,
    • Set hibernate.jdbc.lob.non_contextual_creation=true in your persistence.xml

解决方案是将该行添加到属性文件中(如果您不使用spring,则添加类似内容)

The solution is to add this line in your property file (or something similar if your are not using spring)

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults= false

因此,您的application.yml应该如下所示:

So, your application.yml should looks like:

spring:
    application:
      name: employee-service

    datasource:
      url: jdbc:postgresql://localhost:5432/db_development
      platform: POSTGRESQL
      username: ...
      password: ...

    jpa:
      hibernate:
        ddl-auto: create-drop
        dialect: org.hibernate.dialect.PostgreSQL9Dialect
        show_sql: true
      properties.hibernate.temp.use_jdbc_metadata_defaults: false


server:
  port: 8080

参考:

https://o7planning.org/en/11661/spring-boot-jpa-and-spring-transaction-tutorial

使用c3p0休眠:createClob()尚未实现

感谢 Binakot 的鸣谢.我已经更新了帖子.

Thanks to Binakot for his comment bellow. I have updated the post.

这篇关于Postgres错误方法org.postgresql.jdbc.PgConnection.createClob()未实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:31