126

How can I solve this error:

java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation(LobCreatorBuilderImpl.java:113) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.makeLobCreatorBuilder(LobCreatorBuilderImpl.java:54) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:271) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:114) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at com.divergent.demo.DemoApplication.main(DemoApplication.java:12) ~[classes/:na]



Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
    at org.postgresql.Driver.notImplemented(Driver.java:683) ~[postgresql-42.2.1.jar:42.2.1]
    at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1252) ~[postgresql-42.2.1.jar:42.2.1]
    ... 44 common frames omitted
davidxxx
  • 125,838
  • 23
  • 214
  • 215
Sandeep Malviya
  • 1,399
  • 2
  • 8
  • 7
  • Possible duplicate of [hibernate with c3p0: createClob() is not yet implemented](https://stackoverflow.com/questions/46493500/hibernate-with-c3p0-createclob-is-not-yet-implemented) – davidxxx Apr 05 '18 at 10:25
  • 1
    "hibernate with c32p0..." doesn't mention Spring Boot, although answers do – Pafnucy Jun 13 '18 at 09:47
  • see also: https://stackoverflow.com/questions/65094862/how-to-resolve-method-org-postgresql-jdbc-pgconnection-createblob-is-not-yet/65703651#65703651; createBlob/Clob is currently implemented for Postgres 42.3.0 – jfx Jan 13 '21 at 14:12

9 Answers9

229

Add this property in your application.properties :

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

Reference :

Clément Poissonnier
  • 1,289
  • 2
  • 12
  • 26
Ashutosh
  • 2,827
  • 2
  • 12
  • 11
  • 1
    Didn't work with Spring Boot 2.1.6. It's possible there was a [regression](https://github.com/hibernate/hibernate-orm/pull/2572#issuecomment-494356864). – cstroe Jun 24 '19 at 05:12
  • Worked for 2.1.9 RELEASE. – Utkarsh Oct 05 '19 at 08:22
  • 2
    Didn't work with Spring Boot 2.4.4. Finally I've found that is a hibernates bug, so 1) I've deleted upper configuration + 2) upgrated Hibernate version from `5.2.10.Final` to `5.4.2.Final`. Than started to work. https://stackoverflow.com/questions/55732898/how-to-resolve-org-postgresql-jdbc-pgconnection-createclob-is-not-yet-implemen – EnGoPy Apr 16 '21 at 22:25
46

This is an issue of Hibernate, as a workaround, you can use the following flag. Then set up the following config in your properties:

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

For Spring boot 2.x.x this flag simply disable contextual LOB creation, but if you really want to know the properly answer check UPDATE V1.

UPDATED V1

This was a Hibernate issue. If you use Spring Boot latest version from 2.0.x until 2.1.x includes Hibernate 5.3.10.final you can take a look here but this issue was fixed on Hibernate version 5.4.0.CR1 then you need to add that dependency or if it is possible the latest version:

For Gradle:

compile('org.hibernate:hibernate-core:5.4.2.Final')

For Maven:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.2.Final</version>
</dependency>

UPDATED V2 "SPRING BOOT 2.2.0.M(1-4)"

In addition Spring boot v2.2.0.Mx includes now Hibernate v5.4.x then this issue was fixed for these versions.

Jonathan JOhx
  • 5,784
  • 2
  • 17
  • 33
  • 1
    Cool I added more information about it and updated supporting of versions for spring boot. @ShekhFirozAlam – Jonathan JOhx Jul 09 '19 at 15:42
  • In Spring Boot 2.2.1.RELEASE, still got the problem. mohammad hejazi's answer worked. https://stackoverflow.com/a/54288767/4766882 – Dennis Kim Apr 29 '20 at 07:52
32

I had the similar issue. I followed this solution and it worked for me

http://vkuzel.blogspot.com/2016/03/spring-boot-jpa-hibernate-atomikos.html

# Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details.
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

# Because detection is disabled you have to set correct dialect by hand.
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
18

Solved by using following Yaml configuration:

spring:
  jpa:
    properties:
      hibernate:
        jdbc:
          lob:
            non_contextual_creation: true
    database-platform: org.hibernate.dialect.PostgreSQL9Dialect
Bhuwan Prasad Upadhyay
  • 2,916
  • 1
  • 29
  • 33
13

Solved by adding hibernate.properties with

hibernate.jdbc.lob.non_contextual_creation=true

Other solutions with application.properties didn't work. This can be also done via XML hibernate.cfg.xml

Spring Boot version: 2.0.2.RELEASE

Pafnucy
  • 608
  • 1
  • 13
  • 17
  • 1
    are you sure you started with spring.jpa ? this works fine in 2.0.3 for me – Kalpesh Soni Jul 24 '18 at 16:00
  • @KalpeshSoni sorry, can't answer. Its a spring-boot project with business dependency of another project, in which persistence stuff is defined. Hard to reproduce this setup to figure it out. – Pafnucy Oct 18 '18 at 10:46
8
spring:      
  jpa:
    properties:
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false
        jdbc:
          lob:
            non_contextual_creation: true

with

use_jdbc_metadata_defaults: false

or

non_contextual_creation: true

two items work fine

Apostolos
  • 10,033
  • 5
  • 24
  • 39
mohammad hejazi
  • 171
  • 1
  • 6
4

Faced the same problem with Spring Boot version: 2.1.x.RELEASE too. it worked with:

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true 
Roy Scheffers
  • 3,832
  • 11
  • 31
  • 36
0

I was struggling with this stuff for a day.

  • Spring boot version 2.2.5

  • Postgres: 42.2.10

  • Version of Postgres on server: PostgreSQL 11.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.3, 64-bit

I was using Spring JPA data with Hibernate configuration. Using sessionFactory.

Hibernate configuration:

@Bean(name = "sessionFactory")
@Primary
public LocalSessionFactoryBean sessionFactory(){
    LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(assetHealthDataSource);
    sessionFactoryBean.setMappingDirectoryLocations(new Resource[]{new ClassPathResource("mappings")});
    sessionFactoryBean.setHibernateProperties(hibernateProperties());

    return sessionFactoryBean;
}

Hibernate Properties:

private final Properties hibernateProperties() {
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty(
            "hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
    hibernateProperties.setProperty(
            "hibernate.jdbc.lob.non_contextual_creation", "true");
    hibernateProperties.setProperty(
            "hibernate.temp.use_jdbc_metadata_defaults", "false");
    hibernateProperties.setProperty(
            "hibernate.show_sql", environment.getProperty("assetHealthDataSource.hibernate.showSQL"));
    hibernateProperties.setProperty(
            "hibernate.format_sql", environment.getProperty("assetHealthDataSource.hibernate.formatSQL"));
    hibernateProperties.setProperty(
            "hibernate.transaction.auto_close_session", "false");
    hibernateProperties.setProperty(
            "hibernate.hibernate.connection.release_mode", "auto");
    hibernateProperties.setProperty(
            "hibernate.hikari.maximumPoolSize", "3");
    hibernateProperties.setProperty(
            "hibernate.default_schema", "MY_SCHEMA");

    return hibernateProperties;
}

But everything was not working properly. Willing to see any suggestion that can help to solve this out. Thank you very much.

Hung Bang Quan
  • 151
  • 2
  • 9
  • ak, it was solved. I would like to confirm that this problem would not occur in Springboot 2.2.5 and Hibernate 4.2.14 Final, I got the error because there is an Oracle driver in the application, maybe it led to conflict. Thank you. – Hung Bang Quan Jun 16 '20 at 09:51
0

For anyone searching for a Grails answer (3.3 and up), @Ashutosh's answer worked for me but what caught me out is in your application.yml file, you omit the spring.jpa.properties prefix. Add it to the hibernate section, where you're likely to have your dialect specified:

hibernate:
    dialect: <your dialect>
    jdbc:
        lob:
            non_contextual_creation: true
    temp:
        use_jdbc_metadata_defaults: false
Cyntech
  • 5,362
  • 6
  • 33
  • 47