Java 未知数据类型:“未知”;JSON";
我们试图在hibernate中定义一个json列,如下所示: 实体类:Java 未知数据类型:“未知”;JSON";,java,json,hibernate,h2,Java,Json,Hibernate,H2,我们试图在hibernate中定义一个json列,如下所示: 实体类: @TypeDef( name="CustomType", CustomJSONType.class) ... @Type( name = "CustomType") @Column private JSONObject myColumn; ... CustomJSONType类实现了UserType 应用程序运行时,日志会显示以下错误跟踪: 2018-02-06 08:46:44.0
@TypeDef( name="CustomType", CustomJSONType.class)
...
@Type( name = "CustomType")
@Column
private JSONObject myColumn;
...
CustomJSONType
类实现了UserType
应用程序运行时,日志会显示以下错误跟踪:
2018-02-06 08:46:44.067 ERROR [company-operations-module,,,] 11804 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: create table operation (id int4 not null, creation timestamp not null, type varchar(50) not null, request_data json not null, response_data json, status varchar(50) not null, user_id varchar(30), primary key (id))
2018-02-06 08:46:44.067 ERROR [operations-module,,,] 11804 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : Unknown data type: "JSON" Unknown data type: "JSON"; SQL statement: create table operation (id int4 not null, creation timestamp not null, type varchar(50) not null, request_data json...) [50004-190]
2018-02-06 08:46:44.067 INFO [operations-module,,,] 11804 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
有什么想法吗?
提前感谢。H2数据库不支持JSON数据类型。所以,你的测试失败了
我建议您解决的一项工作是将JSON列存储为文本,并根据需要处理数据 还可以使用“创建域”选项将H2配置为将JSON作为文本。 例如,在连接URL中:
jdbc:h2:~/test;AUTO_SERVER=TRUE;INIT=create domain if not exists json as text
您正在使用哪个数据库?您的数据库是否支持JSON数据类型?如果不是,那么在这种情况下,您可能必须实现转换器。数据库是Posgress,但在执行测试时会发生错误。在本例中,我们使用的是内存中的hibernate数据库。我发现这个,它使用H2数据库。我可以建议您的另一个解决方法是使用Postgres Docker映像来运行测试。这会增加一些开销,但值得一试。太棒了!如果答案解决了您的问题,请务必接受。