title: Hibernate: Map Two Columns to a HashMap's Key and Value
body: <p>I have a database with an object, which has translations.</p>
  
  <p>There are 2 tables: table Object which has <code>id</code> and more properties and table 'object_translation' which has <code>object_id</code>, <code>language</code> (varchar) and <code>translation</code> (varchar)</p>
  
  <p>I would like to map this to </p>
  
  <pre><code>public class Object {
      private Map&lt;Language, String&gt; translations
  }
  </code></pre>
  
  <p>Where language is an enum in code and a string in the DB.</p>
  
  <p>Is this possible with annotations? or do I need to create either <code>Collection&lt;QuestionTranslation&gt;</code> or write my own hibernate mapping functions in the DAO (I'm using spring-data, so I would prefer to keep it nice and clean as interfaces and annotations)</p>
  
  <p>Versions: spring-boot 2 with provided hibernate from spring-boot-starter:</p>
  
  <pre><code>spring boot: &lt;version&gt;2.0.3.RELEASE&lt;/version&gt;
  &lt;hibernate.version&gt;5.2.17.Final&lt;/hibernate.version&gt;
  &lt;hibernate-jpa-2.1-api.version&gt;1.0.2.Final&lt;/hibernate-jpa-2.1-api.version&gt;
  </code></pre>
  
  <p>So far I have this:</p>
  
  <pre><code>@OneToMany
  @JoinTable(name = "object_translation", joinColumns = {@JoinColumn(name = "object_id", referencedColumnName = "id")})
  @MapKey(name = "language")
  @MapKeyEnumerated(EnumType.STRING)
  private Map&lt;Language, String&gt; translations;
  </code></pre>
  
  <p>But how do I map the value as well? (for clarification: the String value should be the translation column in the DB)</p>
  
  <p>Because I don't have a primary-key, this should theoretically be possible?</p>
  
  <p>Thanks in advance!</p>