131

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
3

9 Answers 9

235

Add this property in your application.properties :

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

Reference :

3
  • 1
    Didn't work with Spring Boot 2.1.6. It's possible there was a regression.
    – cstroe
    Jun 24, 2019 at 5:12
  • Worked for 2.1.9 RELEASE.
    – Utkarsh
    Oct 5, 2019 at 8: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. stackoverflow.com/questions/55732898/…
    – EnGoPy
    Apr 16, 2021 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.

2
  • 1
    Cool I added more information about it and updated supporting of versions for spring boot. @ShekhFirozAlam Jul 9, 2019 at 15:42
  • In Spring Boot 2.2.1.RELEASE, still got the problem. mohammad hejazi's answer worked. stackoverflow.com/a/54288767/4766882
    – Dennis Kim
    Apr 29, 2020 at 7:52
33

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
1
  • This worked for me. However, I used spring.jpa.database=POSTGRESQL instead of the dialect.
    – cbmeeks
    Mar 22, 2018 at 14:15
19

Solved by using following Yaml configuration:

spring:
  jpa:
    properties:
      hibernate:
        jdbc:
          lob:
            non_contextual_creation: true
    database-platform: org.hibernate.dialect.PostgreSQL9Dialect
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

2
  • 1
    are you sure you started with spring.jpa ? this works fine in 2.0.3 for me Jul 24, 2018 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, 2018 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

1
  • Why should we use the above configs? what do they do?
    – chapskev
    Feb 18, 2022 at 0:33
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 
1
  • I did, but it was not working. Is there the other way? Jun 16, 2020 at 9:07
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.

1
  • 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. Jun 16, 2020 at 9: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

Not the answer you're looking for? Browse other questions tagged or ask your own question.