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

编程入门 行业动态 更新时间:2024-10-19 23:44:41
本文介绍了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.apachemons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868) at org.apachemons.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.

解决方案:

  • 使用较新的向后兼容版本更新您的postgressql驱动程序.
    • 在application.yml中设置spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true或
    • 在persistence.xml中设置hibernate.jdbc.lob.non_contextual_creation=true
    • 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

        参考:

        o7planning/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()未实现

    本文发布于:2023-10-25 08:40:37,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1526460.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:错误   方法   org   Postgres   PgConnection

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!