title: Hibernate annotated many-to-one not adding child to parent Collection
body: <p>I have the following annotated Hibernate entity classes:</p>
  
  <pre><code>@Entity
  public class Cat {
      @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) @Id
      private Long id;
  
      @OneToMany(mappedBy = "cat", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private Set&lt;Kitten&gt; kittens = new HashSet&lt;Kitten&gt;();
  
      public void setId(Long id) { this.id = id; }
      public Long getId() { return id; }
      public void setKittens(Set&lt;Kitten&gt; kittens) { this.kittens = kittens; }
      public Set&lt;Kitten&gt; getKittens() { return kittens; }
  }
  
  @Entity
  public class Kitten {
      @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) @Id
      private Long id;
  
      @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private Cat cat;
  
      public void setId(Long id) { this.id = id; }
      public Long getId() { return id; }
      public void setCat(Cat cat) { this.cat = cat; }
      public Cat getCat() { return cat; }
  }
  </code></pre>
  
  <p>My intention here is a bidirectional one-to-many/many-to-one relationship between Cat and Kitten, with Kitten being the "owning side".</p>
  
  <p>What I want to happen is when I create a new Cat, followed by a new Kitten referencing the Cat, <strong>the Set of kittens on my Cat should contain the new Kitten</strong>. However, this <strong>does not happen</strong> in the following test:</p>
  
  <pre><code>@Test
  public void testAssociations()
  {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      Transaction tx = session.beginTransaction();
  
      Cat cat = new Cat();
      session.save(cat);
  
      Kitten kitten = new Kitten();
      kitten.setCat(cat);
      session.save(kitten);
  
      tx.commit();
  
      assertNotNull(kitten.getCat());
      assertEquals(cat.getId(), kitten.getCat().getId());
      assertTrue(cat.getKittens().size() == 1); // &lt;-- ASSERTION FAILS
      assertEquals(kitten, new ArrayList&lt;Kitten&gt;(cat.getKittens()).get(0));
  }
  </code></pre>
  
  <p>Even after re-querying the Cat, the Set is still empty:</p>
  
  <pre><code>// added before tx.commit() and assertions
  cat = (Cat)session.get(Cat.class, cat.getId());
  </code></pre>
  
  <p>Am I expecting too much from Hibernate here? Or is the burden on me to manage the Collection myself? The <a href="http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e1591" rel="noreferrer">(Annotations) documentation</a> doesn't make any indication that I need to create convenience <code>addTo*</code>/<code>removeFrom*</code> methods on my parent object.</p>
  
  <p>Can someone please enlighten me on what my expectations should be from Hibernate with this relationship? Or if nothing else, point me to the correct Hibernate documentation that tells me what I should be expecting to happen here.</p>
  
  <p><strong>What do I need to do to make the parent Collection automatically contain the child Entity?</strong></p>