【发布时间】:2018-07-16 06:14:00
【问题描述】:
我们正在尝试在hibernate中定义一个json列,如下所示:
实体类:
@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
有什么想法吗? 提前致谢。
【问题讨论】:
-
您使用的是哪个数据库?您的数据库是否支持 JSON 数据类型?如果不是,那么在这种情况下,您可能必须实施转换器。
-
数据库是Posgress,但是我们执行测试的时候出现错误。在本例中,我们使用的是内存中的休眠数据库。
-
我找到了这个,这个使用 H2 数据库。 stackoverflow.com/questions/39620317/…