How to match string [] in sleep mode

How would you display the following class in sleep mode:

private class Book { private int id; private String title; private String[] chapterTitles; //Constructor, Getters and Setters } 

I matched collections and primitive arrays in Hibernate, but how to do it with String [] ? My hibernation tools are stopped using a "NullPointerException", so I cannot generate mappings. And I have googled, but could not find.

+6
source share
2 answers

I don’t know how to do this with annotations and personally, I don’t think it is a good idea and you should use List<String> , but you can do it using xml matching.

You must use <array>

 <array name="chapterTytles" table="Titles"> <key column="title_ID" /> <index column="tytle_index" /> <element column="tytle_name" type="string" /> </array> 
+7
source

You can do this by creating a custom value type , although I personally would prefer to change my design and use a list instead.

+5
source

Source: https://habr.com/ru/post/898067/


All Articles