在 postgres spring-boot + eclipselink 中另存为 JSON 数据类型的替代解决方案
Alternate solution to save as JSON datatype in postgres spring-boot + eclipselink
我将 eclipselink 2.6 与 spring-boot JPA 一起用于 postgres 中的持久性。
我将对象列表作为 database.Acording 中的 JSON 列保存到此解决方案:eclipselink + @convert(json) + postgres + list property
我能够将数据保存在 postgres 中。
当该列为空时,我得到这个异常:
Caused by: org.postgresql.util.PSQLException: ERROR: column "sample_column" is of type json but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
我可以通过这个答案解决这个问题:
Q1:除了设置 this 属性 stringtype=unspecified
int url spring.datasource.url=jdbc:postgresql://localhost:5432/dbname?stringtype=unspecified
是否有替代解决方案
Q2:如果没有,如何在 spring-boot 的 application.prooerties 中设置 stringtype=unspecified
而不是将其嵌入 spring.datasource.url
答案是肯定的,但是implementation-specific。
例如,在Tomcat中,这个属性被称为connectionProperties
,因此你会写:
spring.datasource.tomcat.connection-properties: stringtype=unspecified
来自 the Spring-Boot documentation.
It is also possible to fine-tune implementation-specific settings using their respective prefix (spring.datasource.tomcat., spring.datasource.hikari., spring.datasource.dbcp.* and spring.datasource.dbcp2.*). Refer to the documentation of the connection pool implementation you are using for more details.
如果您使用的是 spring-boot 1.4.1 或更高版本,
在资源文件夹中添加一个data.sql文件,
-- IN H2 database, create a column as 'OTHER' data type,
-- if H2 fails to create a column as 'JSON' data type.
CREATE DOMAIN IF NOT EXISTS JSON AS OTHER;
此 .sql 文件将在您的应用程序启动期间执行,并将在 table 中为 [=17] 创建数据类型为 others
的列=]'json' H2数据库中的数据类型列。
我将 eclipselink 2.6 与 spring-boot JPA 一起用于 postgres 中的持久性。
我将对象列表作为 database.Acording 中的 JSON 列保存到此解决方案:eclipselink + @convert(json) + postgres + list property 我能够将数据保存在 postgres 中。
当该列为空时,我得到这个异常:
Caused by: org.postgresql.util.PSQLException: ERROR: column "sample_column" is of type json but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
我可以通过这个答案解决这个问题:
stringtype=unspecified
int url spring.datasource.url=jdbc:postgresql://localhost:5432/dbname?stringtype=unspecified
是否有替代解决方案
Q2:如果没有,如何在 spring-boot 的 application.prooerties 中设置 stringtype=unspecified
而不是将其嵌入 spring.datasource.url
答案是肯定的,但是implementation-specific。
例如,在Tomcat中,这个属性被称为connectionProperties
,因此你会写:
spring.datasource.tomcat.connection-properties: stringtype=unspecified
来自 the Spring-Boot documentation.
It is also possible to fine-tune implementation-specific settings using their respective prefix (spring.datasource.tomcat., spring.datasource.hikari., spring.datasource.dbcp.* and spring.datasource.dbcp2.*). Refer to the documentation of the connection pool implementation you are using for more details.
如果您使用的是 spring-boot 1.4.1 或更高版本,
在资源文件夹中添加一个data.sql文件,
-- IN H2 database, create a column as 'OTHER' data type,
-- if H2 fails to create a column as 'JSON' data type.
CREATE DOMAIN IF NOT EXISTS JSON AS OTHER;
此 .sql 文件将在您的应用程序启动期间执行,并将在 table 中为 [=17] 创建数据类型为 others
的列=]'json' H2数据库中的数据类型列。