title: one to many unidirectional hibernate mapping doesn't save the child table
body: <p>I have two tables called <code>Person</code> and <code>Address</code>. These tables I mapped <em>one to many</em> with hibernate using annotation. </p>
  
  <p>Then in my parent entity <code>Person</code> I create a <code>Set&lt;Address&gt;</code> to hold the child class. After that I create a set of address and set to <code>Person</code> entity and also set Person's own values.</p>
  
  <p>My problem is that when I am save the parent entity child does not save in DB.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Person.java</strong></p>
  
  <pre><code>@Entity
  @Table(name="PERSON")
  public class Person {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name="personId")
      private int id;
      @Column(name="personName")
      private String name;
      @OneToMany(cascade =CascadeType.ALL,fetch = FetchType.EAGER)
      @JoinColumn(name="personId") 
      private Set &lt;Address&gt; addresses;
  </code></pre>
  
  <p><strong>Address.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "ADDRESS")
  public class Address {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "addressId")
      private int id;
      @Column(name = "address")
      private String address;
      @Column(name="personId") 
      private int personid;
  </code></pre>
  
  <p>My DAO:</p>
  
  <pre><code>   public Person addNewPerson() {
      Person per = new Person();
      per.setName("aaaa person");
      Set&lt;Address&gt; addressSet = new HashSet&lt;Address&gt;();
      for(int i = 0; i&lt;=3;i++){
          Address ad = new Address();
          ad.setAddress("aaa "+i);
          addressSet.add(ad);
  
      }
       per.setAddresses(addressSet);
       getHibernateTemplate().save(per );
      }
  </code></pre>
  
  <p>Here person is adding in my table but address is not saved. Why?</p>
  
  <p>bidirectional it is possible, but in unidirectional is my problem </p>