title: Problem with saveOrUpdate() in hibernate
body: <p>Recently i am started using hibernate. to insert or update i am using <code>saveOrUpdate()</code> function.
  If i update an entry i works fine. But, with new entry hibernate generate a Query. Buts nothing gets updated in the table. </p>
  
  <p>My scenario is like this,</p>
  
  <p>i am using Many to One &amp; One to Many relationship between two tables<code>[Expense, Category]</code>
  For update or insert, i am creating two objects<code>(Expense expense, Category category)</code> from the
  client side. In the server side, i set <code>category</code> object with <code>expense</code> object.</p>
  
  <pre><code>public void upDateExpenseTable(Expens expense, Category category) {
  
      expense.setCategory(category);
      Session session = Main.getSession();
      try{
          System.out.println("Inside Update Try Block");
          session = Main.getSession();
          Transaction tr = session.beginTransaction();
          session.saveOrUpdate(expense);
          tr.commit();
  
      }
      finally{
          session.close();
      }
  }
  </code></pre>
  
  <p>Object structure is like, <code>catogery.catId, category.catName</code> &amp; 
  <code>expense.expnsId, expense.expnsName, expense.amount, expense.status, expense.userName</code>.</p>
  
  <p>But there is another one column in <code>Expense</code> Table <code>cat_id</code>. Its is through mapping annotation. But i dont have any property for that in Expense entity. 
  When inserting new data, i am not giving any Id.</p>
  
  <p>Any suggestions!!!</p>
  
  <pre><code>public class Expens implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private int expnsId;
  private int amount;
  private String date;
  private String status;
  private String userName;
  
      @ManyToOne
  @JoinColumn(name = "cat_id") 
  private Category category;
      //Setter Getter
  
  }
  </code></pre>
  
  <p><strong>Category Classs</strong></p>
  
  <pre><code>public class Category{
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private int catId;
  private String catName;
  
  @OneToMany(targetEntity=Expens.class, mappedBy = "category", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
  private List&lt;Expens&gt; expenses;
  }//Setters Getters ommited.
  </code></pre>