当项目同时使用MySQL和PostgreSQL时,从JsonStringType切换为JsonBinaryType

编程入门 行业动态 更新时间:2024-10-27 09:46:35
本文介绍了当项目同时使用MySQL和PostgreSQL时,从JsonStringType切换为JsonBinaryType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当需要从PostgreSQL切换到MariaDB/MySql时,列json出现问题.我使用Spring Boot + JPA + Hibernate + hibernate-types-52.我要映射的表是这样的:

I have a problem with column json when it's necessary to switching from PostgreSQL to MariaDB/MySql. I use Spring Boot + JPA + Hibernate + hibernate-types-52. The table i want to map is like this:

CREATE TABLE atable( ... acolumn JSON, ... );

好,它适用于PostgreSQL和MariaDB/MySql.问题是当我想部署一个可以轻松地从一个切换到另一个的应用程序时,因为PostgreSQL和MySQL/MariaDB的正确的hibernate-types-52实现是不同的 这适用于MySQL/MariaDB

Ok it works for PostgreSQL and MariaDB/MySql. The problem is when i want to deploy an application that switch easly from one to another because the correct hibernate-types-52 implementation for PostgreSQL and MySQL/MariaDB are different This works on MySQL/MariaDB

@Entity @Table(name = "atable") @TypeDef(name = "json", typeClass = JsonStringType.class) public class Atable { ... @Type(type = "json") @Column(name = "acolumn", columnDefinition = "json") private JsonNode acolumn; ... }

这适用于PosgreSQL

This works on PosgreSQL

@Entity @Table(name = "atable") @TypeDef(name = "json", typeClass = JsonBinaryType.class) public class Atable { ... @Type(type = "json") @Column(name = "acolumn", columnDefinition = "json") private JsonNode acolumn; ... }

任何一种从JsonBinaryType切换到JsonStringType的解决方案(或解决此问题的任何其他解决方案)都是值得的.

Any kind of solutions to switch from JsonBinaryType to JsonStringType (or any other solution to solve this) is appreciated.

推荐答案

从Hibernate Types项目的 2.11.0 版本开始,您只需使用 JsonType ,可与PostgreSQL,MySQL,Oracle,SQL Server或H2配合使用.

Starting with the 2.11.0 version of the Hibernate Types project, you can just use the JsonType, which works with PostgreSQL, MySQL, Oracle, SQL Server, or H2.

因此,请使用 JsonType 代替 JsonBinaryType 或 JsonStringType

@Entity @Table(name = "atable") @TypeDef(name = "json", typeClass = JsonType.class) public class Atable { @Type(type = "json") @Column(name = "acolumn", columnDefinition = "json") private JsonNode acolumn; }

就是这样!

更多推荐

当项目同时使用MySQL和PostgreSQL时,从JsonStringType切换为JsonBinaryType

本文发布于:2023-10-29 03:02:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   MySQL   PostgreSQL   JsonStringType   JsonBinaryType

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!