How to map a String[] in hibernate
How would you map the following class in hibernate:
private class Book {
private int id;
private String title;
pri开发者_如何学Pythonvate String[] chapterTitles;
//Constructor, Getters and Setters
}
I have mapped Collections and primitive arrays in Hibernate, but how do I do it with a String[]? My hibernate tools stops with a 'NullPointerException' thereby I am unable to generate the mappings. And I have googled but couldn't find any.
I have no clue how to do it with Annotations and personally, I don't think it's good idea and you should use List<String>
however you can do it using xml mapping.
You should use <array>
<array name="chapterTytles" table="Titles">
<key column="title_ID" />
<index column="tytle_index" />
<element column="tytle_name" type="string" />
</array>
You can do it by creating a custom value type, although I would personally prefer to change your design and use a List instead.
精彩评论