I am looking to create json data type column in MySQL via hibernate during startup. I don't want any kind of transformation while saving or fetching data. I just want to store json string ( rather than an object) into json column.
How could I achieve via hibernate.
Any idea or hint, please ?
-
MySQL will reconstruct your JSON value (the value retrieved may differ from the value saved - in components ordering) if you'll use JSON datatype column. Is it safe for you? If not then use VARCHAR/TEXT datatype instead.Akina– Akina2020年06月26日 06:59:10 +00:00Commented Jun 26, 2020 at 6:59
-
@Akina At max I assume, MySQL would reorder the keys of JSON and nothing much. I am okay with it. The problem lies in that Hibernate does not identify "JSON" type.Tarun– Tarun2020年06月26日 08:51:54 +00:00Commented Jun 26, 2020 at 8:51
-
At max I assume, MySQL would reorder the keys of JSON and nothing much. That's true. For some OPs the physical order makes sense somewhy...Akina– Akina2020年06月26日 09:31:52 +00:00Commented Jun 26, 2020 at 9:31
-
@Akina Do you know how could I introduce JSON type in hibernate ?Tarun– Tarun2020年06月26日 09:55:18 +00:00Commented Jun 26, 2020 at 9:55
-
See, for example, this.Akina– Akina2020年06月26日 10:05:51 +00:00Commented Jun 26, 2020 at 10:05
1 Answer 1
I used the following xml property ("sql-type") to create json data type: E.g:
<property name="template">
<column name="template" sql-type="json"/>
</property>
This was enough for me as I am not looking for transformation between json and object. For transformation, one can create converter.
Thanks to @Akina for helping me with useful links and suggestion.