Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

<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:

@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 Postgres queries?

like image 329
Nirav Patel Avatar asked May 11 '17 01:05

Nirav Patel


People also ask

Why can’t I create a CLOB in PostgreSQL?

Looking at the stack trace it is clear that the original exception originated postgresql jdbc driver. It turns out that Postgresql doesn’t support the Clob data type, the JDBC interface expects any implementing driver to be able to create a Clob or throw java.sql.SQLFeatureNotSupportedException, which is exactly what Postgresql JDBC does.

Why does atomikos throw hibernate connection error in PostgreSQL?

These exceptions appears because JPA (Hibernate) supported by Atomikos is trying to verify PostgreSQL CLOB feature. This feature is not implemented by JDBC driver, so driver throws an unimportant exception. Unfortunately Atomikos has an exception listener which marks a connection as erroneous if any exception occurs.

Can I use Spring Boot with JPA and PostgreSQL?

Spring Boot + JPA (Hibernate) + Atomikos + PostgreSQL = exception! If you try to use combination of Spring Boot (1.3.3), Spring Data JPA, Atomikos and PostgreSQL database you will probably experience an exception during start of an application.

How do I connect to a hibernate database without PostgreSQL?

If you're not using PostgreSQL, remember to specify the connection URL and the Hibernate dialect for your database on lines 4 and 18 respectively. Refer to the official documentation to find out all the dialects supported by Hibernate.


3 Answers

TL;DR

  • 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

It's a known error in JBoss community.

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

Solution:

  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
  2. If it's not working see this trick below:

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

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

Reference:

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

hibernate with c3p0: createClob() is not yet implemented

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

like image 93
KeyMaker00 Avatar answered Sep 19 '22 07:09

KeyMaker00


put this in to application.properties

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
like image 21
superup Avatar answered Sep 22 '22 07:09

superup


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

like image 22
Craig Ringer Avatar answered Sep 20 '22 07:09

Craig Ringer