title: JPA Cascade Persist not working
body: <p>I have two classes : Expenditure and Category. An Expenditure can have multiple Categories. I wish to implement Cascade save of all Categories(children) with Expenditure(parent). But unable to achieve this.On persisting Expenditure record no Category entries are created. Please let me know what I am doing wrong. Here are my classes:</p>
  
  <pre><code>@Entity
  @Table(name="EXPENDITURE")
  public class Expenditure {
  
      private Long id;
  
      @OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE}, mappedBy="expenditure")
      private Set&lt;Category&gt; associatedCategories = new HashSet&lt;Category&gt;();   
  
      public Expenditure() {  }
  
      @Id @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="EXPENDITURE_ID")
      public Long getId() {
          return id;
      }
      public void setId(Long id) {
          this.id = id;
      }
  
      public void addCategory(Category category)
      {
          this.associatedCategories.add(category);
          category.setExpenditure(this);      
      }
  }
  
  @Entity
  @Table(name="CATEGORY")
  public class Category {
  
      @Id @GeneratedValue
      @Column(name="CATEGORY_ID")
      private Long id;
      private String name;
  
      @ManyToOne(targetEntity=Expenditure.class)
      private Expenditure expenditure;
  
      public Category(){}
      public Category(String name)
      {
          this.name = name;
      }
      public Category(String name,String description)
      {
          this.name = name;
      }
      @Column(name="NAME")
      public String getName() {
          return name;
      }       
  
      public Expenditure getExpenditure() {
          return expenditure;
      }
      public void setExpenditure(Expenditure expenditure) {
          this.expenditure = expenditure;
      }
  </code></pre>