【问题标题】:inserting json string from spring application into postgres jsonb将来自spring应用程序的json字符串插入postgres jsonb
【发布时间】:2018-05-13 01:12:52
【问题描述】:

我想将没有预定义结构(即键值格式不固定)的 json 字符串插入到具有 jsonb 数据类型的 postgres 列中。我的应用程序使用 HikariCP 和 JPA。

之前我在 postgres 中使用了以下通用转换操作来实现上述目的,但我的 DBA 不推荐它,因为它从根本上改变了 varchar 数据类型。

CREATE CAST (character varying AS jsonb) WITH INOUT AS IMPLICIT;

在寻找应用程序端替代方案时,我遇到了将 stringtype 设置为未指定,如下所示

spring:   
  profiles: development   
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://127.0.0.1/mydb
    username: my_user
    password: 'my_password'
    hikari:
      auto-commit: true
      maximumPoolSize: 2
      leakDetectionThreshold: 60000
    tomcat:
      connection-properties: stringtype=unspecified

上述配置没有帮助。连接属性似乎不是数据源的直接属性。论坛上的各种答案只是告诉您在 connection-properties 中设置 stringtype=unspecified 但一个明确的工作答案会更有帮助。

【问题讨论】:

    标签: postgresql spring-boot spring-data-jpa hikaricp


    【解决方案1】:

    边想边想,这个属性一定要设置HikariCP。当我查看它允许我设置的各种参数时,我遇到了数据源属性。以下是我发现的解决上述问题的方法

    hikari:
      data-source-properties: stringtype=unspecified
    

    【讨论】:

    • 对于那些正在寻找扁平化版本的人spring.datasource.hikari.data-source-properties.stringtype=unspecified
    猜你喜欢
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 2016-06-30
    • 2021-02-02
    • 1970-01-01
    相关资源
    最近更新 更多