0

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 ?

asked Jun 26, 2020 at 6:15
10
  • 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. Commented 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. Commented 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... Commented Jun 26, 2020 at 9:31
  • @Akina Do you know how could I introduce JSON type in hibernate ? Commented Jun 26, 2020 at 9:55
  • See, for example, this. Commented Jun 26, 2020 at 10:05

1 Answer 1

0

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.

answered Jun 26, 2020 at 11:52
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.