title: Map problem with JPA / Hibernate / PG
body: <p>I have two entities, Entity1 and Entity2, on a one to many relationship. On Entity1 I have a map which contains  entries.  </p>
  
  <p>The code I use to persist a new Entity1 with some Entity2 on the map is like this:</p>
  
  <pre><code>   Entity1 e1 = new Entity1();  
     Entity2 e2 = null;  
     e1.setE2s(new HashMap&lt;String, Entity2&gt;());
     for (String key : someKeySet()){
        e2 = new Entity2();
        e2.setCode(key);                      
        e2.setSwhon(true);        
        e2.setE1(e1);
        e1.getE2s(key, e2);       
        em.persist(e1.getE2s().get(key));         
  
      }       
      em.persist(e1);
      em.flush();
  </code></pre>
  
  <p>and here is a exctract of the entities:</p>
  
  <pre><code>@Entity
  @Table(name = "wm_Entities1")  
  public class Entity1 implements Serializable {  
     private static final long serialVersionUID = 6592708276573465599L;  
     private Map&lt;String, Entity2&gt; e2s;
     private Long id;  
     @Id  
     @GeneratedValue(strategy=GenerationType.TABLE)  
     public long getId() {  
      return id;  
     }  
     public void setId(long id) {  
      this.id = id;  
     }  
     public void setE2s(Map&lt;String, Entity2&gt; e2s){    
      this.e2s = e2s;
     }       
     @OneToMany(mappedBy = "e1", fetch = FetchType.EAGER)  
     public Map&lt;String, Entity2&gt; getE2s() {  
      return e2s;  
     }  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Entity
  @Table(name = "wm_Entities2")
  public class Entity2 implements Serializable {  
      private static final long serialVersionUID = -6131765066573346790L; 
      private long id;
      private Entity1 e1;
      @Id
      @GeneratedValue(strategy=GenerationType.TABLE)
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
      @ManyToOne()
      @JoinColumn(name="e1_id")
      public Entity1 getE1() {
          return this.e1;
      }
      public void setE1(Entity1 e1) {
          this.e1 = e1;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>This seems to work fine since it inserts both entities on the pg database, but the catch is that it is not creating-saving the MapKey of the e2 on the database (theoretically JPA generates this key), so when I get the e1 back, and I try to get the e2s map from it, I have a:</p>
  
  <blockquote>
    <p>javax.ejb.EJBException:
    org.hibernate.HibernateException: null
    index column for collection:</p>
  </blockquote>
  
  <p>How can I get this MapKey saved??</p>
  
  <p>Note: I'm using JavaEE with JPA/Hibernate, running over JBoss 4.2, with PGSQL DB.</p>