Postgres 错误方法 org.postgresql.jdbc.PgConnection.createClob() 未实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43905119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:34:07  来源:igfitidea点击:

Postgres Error method org.postgresql.jdbc.PgConnection.createClob() is not implemented

javapostgresqljdbcapache-commons-dbcp

提问by Nirav Patel

When I invoke createClobmethod using connection object as shown below:

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

Clob clob = con.createClob();

Following exception is thrown:

抛出以下异常:

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)

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

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

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

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

在 class 中org.postgresql.jdbc.PgConnection, createClob 实现如下所示,抛出异常:

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

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

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

回答by KeyMaker00

TL;DR

TL; 博士

  • Set spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=truein your application.ymlor,
  • Set hibernate.jdbc.lob.non_contextual_creation=truein your persistence.xml
  • 设置spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true在您的 application.yml或,
  • 设置hibernate.jdbc.lob.non_contextual_creation=true在您的 persistence.xml

It's a known error in JBoss community.

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

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

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

Solution:

解决方案

  1. Update your postgressql-driver with a newer backward compatible version.
    • Set spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=truein your application.ymlor,
    • Set hibernate.jdbc.lob.non_contextual_creation=truein your persistence.xml
  2. If it's not working see this trick below:
  1. 使用更新的向后兼容版本更新您的 postgressql 驱动程序。
    • 设置spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true在您的 application.yml或,
    • hibernate.jdbc.lob.non_contextual_creation=true在您的persistence.xml 中设置
  2. 如果它不起作用,请参阅下面的这个技巧:

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

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

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

So, your application.yml should looks like:

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

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

Reference:

参考:

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

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

hibernate with c3p0: createClob() is not yet implemented

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

Thanks to Binakotfor his comment bellow. I have updated the post.

感谢Binakot的评论。我已经更新了帖子。

回答by superup

put this in to application.properties

将其放入application.properties

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

回答by Craig Ringer

PostgreSQL doesn't really have "CLOB". Just use setString(String)or setObject(...)with Types.STRING.

PostgreSQL 并没有真正的“CLOB”。只要使用setString(String)setObject(...)使用Types.STRING

回答by Arthur Kazemi

using spring-boot 2.1.9.RELEASE I added the following and it worked

使用 spring-boot 2.1.9.RELEASE 我添加了以下内容并且它有效

spring:
  jpa:
    properties.hibernate.temp.use_jdbc_metadata_defaults: false
    database-platform: org.hibernate.dialect.PostgreSQL94Dialect