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

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

Clob clob = con.createClob(); 

抛出以下exception。

 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) 

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

  org.postgresql postgresql 42.1.1  

在类org.postgresql.jdbc.PgConnection ,createClob实现如下所示,它抛出exception。

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

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

TL; DR

persistence.xml设置hibernate.jdbc.lob.non_contextual_creation=true

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

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

方案

  1. 使用较新的向后兼容版本更新postgressql-driver。
  2. 在persistence.xml中设置hibernate.jdbc.lob.non_contextual_creation=true
  3. 如果它不起作用,请看下面这个技巧:

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

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

所以,你的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 

参考:

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

hibernate与c3p0:createClob()尚未实现

PostgreSQL实际上没有“CLOB”。 只需对Types.STRING使用setString(String)setObject(...) Types.STRING