9

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

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
vyom
  • 89
  • 1
  • 2

3 Answers3

11

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.

Timon
  • 132
  • 2
  • 9
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
-1

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

Kev
  • 118,037
  • 53
  • 300
  • 385
krumpi
  • 19
  • 2
-1

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.

Kev
  • 118,037
  • 53
  • 300
  • 385
vyom
  • 89
  • 1
  • 2