Multimap in Hibernate

筅森魡賤 提交于 2019-12-23 07:28:51

问题


I need a collection that stores entries as key-value pairs (so I can look up values by a key), but I need one that allows multiple values to share the same key using hibernate


回答1:


A map with multiple values for one key is known as a multimap - there's an implementation in the Apache commons library. Hibernate does not support this kind of collection directly, but it can be extended to do so relatively easily by implementing the UserCollectionType interface. This blog article describes how to do it in detail.




回答2:


There is a multimap over on google collections. I don't know if they are hibernate compatible though.




回答3:


I have also found something relevent

http://commons.apache.org/collections/api-3.1/org/apache/commons/collections/MultiMap.html#get(java.lang.Object)

So can prefer this also.



来源:https://stackoverflow.com/questions/475879/multimap-in-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!