问题描述
这是我一直遇到的问题:
This is a problem I keep on running into:
我想让hibernate管理一个代表集合集合的表。例如:
I would like to have hibernate manage a single table that represents a collection of collections. For example:
- 地图地图
- 集合列表
- 地图列表
例如,我想能够代表:
class OwningClass {
Long entityId;
Map<String, List<Element>> mapOfLists;
}
class Element {
String data_1;
boolean data_2;
}
作为单个表:
OWNER (Foreign key to the owner of this element)
MAP_KEY (varchar(30) )
LIST_INDEX (int)
ELEMENT_DATA_1 (varchar(1020)
ELEMENT_DATA_2 (bit)
没有自定义的hibernate代码似乎不可能,我不介意,但我希望有人有一些
It doesn't seem possible without a custom hibernate code, which I don't mind. But I was hoping someone had some guidance on what that custom code should look like.
- 我应该如何扩展AbstractPersistentCollection?
- CompositeUserType?
可以管理多个表是否正确,但显然从数据库角度来看是不行的。
Its possible to manage if multiple tables are o.k. but obviously that is lame from the db perspective.
推荐答案
在网站上的其他地方找到答案:-)
Found the answer elsewhere on the site :-) Multimap in Hibernate
它指向:
尚未调查该博客文章中的解决方案,但看起来它正在回答我的问题。
Haven't investigated the solution in the blog post yet but looks like it is answering exactly my issue.
这篇关于Hibernate:集合的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!