title: How to persist a property of type List<Object> in JPA?
body: <p>What is the best way to get a List with Objects persisted? I'm using JavaEE 7 with JPA. Object B is also an Entity.</p>
  
  <p><strong>My Model</strong></p>
  
  <pre><code>@Entity
  public class ObjectA implements Serializable {
  
      @Id @GeneratedValue
      private Long id;
  
      // What should I use here?
      private List&lt;ObjectB&gt; objectList;
  
      public ObjectA () {
          this.objectList = new ArrayList&lt;ObjectB&gt;();
      }
  }
  </code></pre>
  
  <p><strong>My JPA Calls</strong></p>
  
  <pre><code>@Stateless
  @JPA
  public class ObjectJPA{
  
      @PersistenceContext(unitName = "ObjectProjectPU")
      private EntityManager em;
  
      // How can I insert a record in the table for objectList here?
      public void insertIntoObjectList(ObjectB objectB) {
          em.persist(objectB); // This must be wrong?
      }
  }
  </code></pre>
  
  <p>What I prefer is that my database table for objectList would look like this:</p>
  
  <pre><code>id (ObjectA_id) | objectB_id     or    id | ObjectA_id | objectB_id
  </code></pre>