title: One-to-many hibernate
body: <p>I have this relation one-to-many.
  This is my ONE table.</p>
  
  <pre><code>private Set&lt;Images&gt; imagesContainer = new HashSet&lt;Images&gt;(0);
  
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "container")
  public Set&lt;Images&gt; getImagesContainer() {
      return this.imagesContainer;
  }
  
  public void setImagesContainer(Set&lt;Images&gt; imagesContainer) {
      this.imagesContainer = imagesContainer;
  }
  </code></pre>
  
  <p>And this is my MANY table:</p>
  
  <pre><code>private Container container;
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "id_container", nullable = false)
  public Container getContainer() {
      return this.container;
  }
  
  public void setContainer(Container container) {
      this.container = container;
  }
  </code></pre>
  
  <p>How can i insert, with hibernate, a new container with MANY container.
  I'll try this:</p>
  
  <pre><code>...
  Set&lt;Images&gt; images=new HashSet&lt;Images&gt;();
  images.add(img1);
  images.add(img2);
  
  Container c = new Container();
  c.setImagesContainer(images);
  ....
  
  @Override
  @Transactional(propagation=Propagation.REQUIRED)
  public void save(Container c){
     getHibernateTemplate().save(c);
  }
  </code></pre>
  
  <p>Don't work !!! I got "nested exception is org.hibernate.exception.DataException: could not insert:..."</p>