我们有一张列很多的大表格。在我们迁移到 MySQL 集群后,由于以下原因,这张表无法被创建:
ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 14000. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs(行大小超出最大值限制。对于所使用的表类型而言,不包括 BLOB 类型,最大行大小为 14000。这包括存储开销,请查看手册。您需要将一些列更改为 TEXT 或 BLOB 类型)
例如:
@Entity @Table (name = "appconfigs", schema = "myproject")
public class AppConfig implements Serializable
{
@Id @Column (name = "id", nullable = false)
@GeneratedValue (strategy = GenerationType.IDENTITY)
private int id;
@OneToOne @JoinColumn (name = "app_id")
private App app;
@Column(name = "param_a")
private ParamA parama;
@Column(name = "param_b")
private ParamB paramb;
}
这是一个用于存储配置参数的表格。我在考虑将一些列合并为一个JSON对象,并将其转换为Java对象。
例如:
@Entity @Table (name = "appconfigs", schema = "myproject")
public class AppConfig implements Serializable
{
@Id @Column (name = "id", nullable = false)
@GeneratedValue (strategy = GenerationType.IDENTITY)
private int id;
@OneToOne @JoinColumn (name = "app_id")
private App app;
@Column(name = "params")
//How to specify that this should be mapped to JSON object?
private Params params;
}
我们定义了以下内容:
public class Params implements Serializable
{
private ParamA parama;
private ParamB paramb;
}
通过使用这个方法,我们可以将所有列合并成一个表格,或者将整个表格拆分为几个表格。个人而言,我更喜欢第一种解决方案。
无论如何,我的问题是如何映射参数列,它是文本,并包含 Java 对象的 JSON 字符串?