title: jpa / hibernate how to map element collection by foreign key with annotations
body: <p>Given these two tables:</p>
  
  <pre><code>CREATE TABLE `soc` (
     `id` INT NOT NULL AUTO_INCREMENT,
     `name` VARCHAR(32),
      PRIMARY KEY (`id`));
  
  CREATE TABLE `soc_attitude` (
     `soc_id` INT NOT NULL,
      `target_soc_id` INT NOT NULL,
      `attitude` INT,
      PRIMARY KEY (`soc_id`,`target_soc_id`));
  </code></pre>
  
  <p>In the <strong>Soc</strong> class, I want to get all rows matching <strong>this.soc_id</strong> from the <strong>soc_attitude</strong> table using a field like this:</p>
  
  <pre><code>private Map&lt;Integer,Integer&gt; attitudes; 
  </code></pre>
  
  <p>Where the key of the map is <strong>target_soc_id</strong> and the value is <strong>attitude</strong>.</p>
  
  <p>I got as far as this:</p>
  
  <pre><code> @Entity
   @Table(name = "soc")
   public class Soc {
      @Id
      @Column( name="id")
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;
  
      @Column(name="name")
      private String name;
  
      @ElementCollection
      @CollectionTable(name="soc_attitude",joinColumns=@JoinColumn(name="soc_id"))
      @Column(name="attitude")
      private Map&lt;Integer,Integer&gt; attitudes; 
  </code></pre>
  
  <p>But I think this will make <strong>soc_id</strong> the key and <strong>attitude</strong> the value.</p>
  
  <p>What annotations do I use? (using Hibernate 4.3.11.Final)</p>