SpringBoot+JPA+PostgreSQL整合问题

理论上本文适用于在使用 JPA+PostgreSQL 时 遇到 org.postgresql.jdbc.PgConnection.createClob() 问题的状况git

环境以及主要依赖版本号

SpringBoot: 2.1.9.RELEASE程序员

PostgreSQL: 11.5github

PostgreSQL-Driver: 42.2.8spring

发生的问题

项目启动时, 报org.postgresql.jdbc.PgConnection.createClob() is not yet implemented 错误, 可是不影响项目运行sql

可是博主有强迫症,必需要解决这个问题,遂Google之,也找到了不少解决方法,譬如添加以下配置:bash

出处:github.com/pgjdbc/pgjd…微信

spring:
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQL9Dialect
    properties:
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false
        jdbc:
          lob:
            non_contextual_creation: true
复制代码

然而很不幸的是,对我都没有效果。app

解决的方法

究其缘由呢,我也找到了以下解释:spring-boot

出处: vkuzel.com/spring-boot…post

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.

那究其根本,是Hibernate验证了一个JDBC没实现的特效致使的,网上广泛的解决方式也是阴暗的屏蔽这个检测特性而已(我我的其实不喜欢这种作法),而且我发现这个问题也有人给Hiberante官方报了issues,那我是否能够经过升级Hibernate来解决呢?

搜了一通,也没见网上有人从这个方向入手,那我就作第一个吃螃蟹的人吧,我先看了看spring-boot-starter-data-jpa中引入的hibernate版本,发现是 5.1.x ,看了下首次发布日期是2016年,考虑到时间关系,我选择升级到 5.4.x 试一下,也省的去官方找发布日志了,先一把梭子先试为敬。

说干就干,我把spring-boot-starter-data-jpa中引入的hibernate版本 先剔除,而后,引入 5.4.x 版本的Hibernate-core,调整后的pom以下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>hibernate-core</artifactId>
            <groupId>org.hibernate</groupId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.3.Final</version>
</dependency>
复制代码

启动项目,问题解决。


知乎专栏:程序员Mk

微信公众号:程序员Mk

相关文章
相关标签/搜索