title: How can i insert a row using hibernate method?
body: <p>I am trying to insert a row into a relation table Stock Category.</p>
  
  <p>I am following this example: <a href="http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/" rel="nofollow noreferrer">http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/</a></p>
  
  <p>Now I already have data in table stock and category.</p>
  
  <p>Later I want to associate a stock and category to each other.</p>
  
  <p>How I can do this without writing a custom sql query?</p>
  
  <p>Is it  possible if I can add StockCategory  like this?</p>
  
  <pre><code>Stock stock = new Stock();
  stock.setStockId(1);
  Category category = new Category();
  category.setCategoryId(1);
  StockCategory stockCategory = new StockCategory();
  
  stockCategory.setStock(stock); //here you need to get the stock object by id 
  stockCategory.setCategory(category1); //here you need to get the category1 object by id
  stockCategory.setCreatedDate(new Date()); //extra column
  stockCategory.setCreatedBy("system"); //extra column
  session.save(stockCategory );
  </code></pre>
  
  <p>Thanks in advance.</p>