title: JPA: How to model Map<String, Set<Object>> (nested collection)
body: <p>this question is related to 
  <a href="https://stackoverflow.com/questions/9784101/is-it-possible-to-map-a-mapstring-listentity-in-jpa">Is it possible to map a map&lt;String,List&lt;Entity&gt;&gt; in JPA?</a> but unfortunately the top-rated answer wasn't much helpful. </p>
  
  <p>Also the related article <a href="http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Nested_Collections.2C_Maps_and_Matrices" rel="nofollow noreferrer">http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Nested_Collections.2C_Maps_and_Matrices</a> captures a different use case as the main entity is related to the MapKey (ProjectType). </p>
  
  <p>In my use case a company uses multiple accounts. The accounts should be grouped by the TYPE of usage (called AccountType). So what I want in CompanyEntity is basically something like</p>
  
  <pre><code>@MapKeyColumn(name = "TYPE")
  @MapKeyEnumerated(EnumType.STRING)
  //Missing JPA-Magic
  private Map&lt;AccountType, Set&lt;AccountEntity&gt;&gt; accounts;
  </code></pre>
  
  <p>My data model: 
  <a href="https://i.stack.imgur.com/MORgD.png" rel="nofollow noreferrer">http://i.stack.imgur.com/MORgD.png</a></p>
  
  <p>How can I achieve this mapping in the most elegant way? </p>
  
  <p>Many thanks upfront!</p>