title: How can I persist a HashMap<Entity, Entity> with JPA
body: <p>Hello I'm a newbie with the JPA-Framework. In my project I use JPA with EclipseLink and DerbyDB. It's all working for me fine. But then I would persist a HashMap, that's my problem.</p>
  
  <p>The HashMap looks like (used in GameArea):</p>
  
  <pre><code>private HashMap&lt;GameObject, ObjectContainer&gt; gameObjects;
  </code></pre>
  
  <p>class GameArea:</p>
  
  <pre><code>@Entity
  public class GameArea implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long OID;
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private HashMap&lt;GameObject, ObjectContainer&gt; gameObjects;
  }
  </code></pre>
  
  <p>class GameObject (the abstract object):</p>
  
  <pre><code>@MappedSuperclass
  public abstract class GameObject implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long OID;
  ...
  }
  </code></pre>
  
  <p>class ObjectContainer (the composite component):</p>
  
  <pre><code>@Entity
  public abstract class ObjectContainer extends GameObject implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long OID;
  ...
  }
  </code></pre>
  
  <p>My HashMap is a lookup table for objects from GameObject to GameObject (as a ObjectContainer).</p>
  
  <p>I've got an exception:</p>
  
  <pre><code>Exception [EclipseLink-163] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DescriptorException
  Exception Description: This mapping's attribute class does not match the collection class.  [class java.util.Hashtable] cannot be assigned to [class java.util.HashMap].
  Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[gameObjects]
  Descriptor: RelationalDescriptor(GameArea --&gt; [DatabaseTable(GAMEAREA)])
  </code></pre>
  
  <p>I don't know what it means...
  I'm not sure with the "OneToMany" relation...</p>
  
  <p>Please can you help me?</p>