如何在休眠中映射 String[]
如何在 Hibernate 中映射以下类:
private class Book {
private int id;
private String title;
private String[] chapterTitles;
//Constructor, Getters and Setters
}
我已经在 Hibernate 中映射了集合和原始数组,但是如何使用 String[] 来实现它?我的休眠工具因“NullPointerException”而停止,因此我无法生成映射。我用谷歌搜索但找不到任何东西。
How would you map the following class in hibernate:
private class Book {
private int id;
private String title;
private 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道如何使用注释来做到这一点,就我个人而言,我认为这不是一个好主意,您应该使用
List
但是您可以使用 xml 映射来做到这一点。您应该使用
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>
您可以通过创建自定义值类型来完成此操作,尽管我个人更愿意更改您的设计并使用列表。
You can do it by creating a custom value type, although I would personally prefer to change your design and use a List instead.