我正在尝试使用带有Postgres的Spring Boot Data JDBC构建API。
我有一个简单的pojo,希望写到一张桌子上
:public final class Test {
private final String id;
private final String definition;
}
该表有2列,即varchar id
列和jsonb definition
列。
使用简单的CRUD存储库保存pojo时,出现以下错误。
ERROR: column "definition" is of type jsonb but expression is of type character varying
通常,解决方案是在application.yml中传递spring.datasourcehikari.connection-properties: stringtype=unspecified
,但我无法使它正常工作。
当我激活hikari的调试日志记录时,我可以看到我为其激活的其他设置(例如池名称)
HikariConfig testPool - configuration:
HikariConfig allowPoolSuspension.............false
HikariConfig autoCommit......................true
HikariConfig catalog.........................none
HikariConfig connectionInitSql...............none
HikariConfig connectionTestQuery.............none
HikariConfig connectionTimeout...............30000
HikariConfig dataSource......................none
HikariConfig dataSourceClassName.............none
HikariConfig dataSourceJNDI..................none
HikariConfig dataSourceProperties............{password=<masked>}
HikariConfig driverClassName................."org.postgresql.Driver"
HikariConfig healthCheckProperties...........{}
HikariConfig healthCheckRegistry.............none
HikariConfig idleTimeout.....................600000
HikariConfig initializationFailTimeout.......1
HikariConfig isolateInternalQueries..........false
HikariConfig jdbcUrl.........................jdbc:postgresql://localhost/test
HikariConfig leakDetectionThreshold..........0
HikariConfig maxLifetime.....................1800000
HikariConfig maximumPoolSize.................10
HikariConfig metricRegistry..................none
HikariConfig metricsTrackerFactory...........none
HikariConfig minimumIdle.....................10
HikariConfig password........................<masked>
HikariConfig poolName........................"testPool"
HikariConfig readOnly........................false
HikariConfig registerMbeans..................false
HikariConfig scheduledExecutor...............none
HikariConfig schema..........................none
HikariConfig threadFactory...................internal
HikariConfig transactionIsolation............default
HikariConfig username........................"test"
HikariConfig validationTimeout...............5000
HikariDataSource testPool - Starting...
HikariPool testPool - Added connection org.postgresql.jdbc.PgConnection@49ba49a7
HikariDataSource testPool - Start completed.
这是我的application.yml:
spring:
datasource:
url: jdbc:postgresql://localhost/test
username: test
hikari:
connection-properties: stringtype=unspecified
poolName: testPool
logging.level.com.zaxxer.hikari: DEBUG
有什么想法吗?
编辑:
这是存储库界面:
@Repository
interface TestRepository extends org.springframework.data.repository.<Test, String>{
}
答案 0 :(得分:1)
我认为您需要使用以下属性文件中的data-source-properties
spring.datasource.hikari.data-source-properties = stringtype =未指定
然后在“定义”的getter上方添加两个注释。
@基本 @Enumerated(EnumType.STRING) 公共字符串getDefinition(){ 返回定义; }