Returning object from create method in DAO
<p>I have following scenario. I want to delegate responsibility of setting creation date to DAO objects.</p>

<pre><code>    Class Product{
     //other fields
     Date creationDate;
    }

    Class ProductDAO{
      private GenericDAO dao;
      public void create(Product p){
         p.setCreationDate(new Date());
         dao.create(p);
      }
    }

    Class Main{
      private ProductDAO productDAO; 
      public void createProduct(){
         Product p = new Product();
         productDAO.create(p);
         LOG.debug(p.getCreationDate());
      } 
    }
</code></pre>

<ol>
<li>Now issue is, when I test createProduct method of main class by
mocking productDAO, how to define the behavior of mock object
'productDAO' so that it sets the creation date and log statement
does not throw NullPointerException?</li>
<li><p>Does above approach seem right? Should I return updated Product
object from create method of ProductDAO class instead of relying on
side effect?</p>

<pre><code> Product create(Product p){
       p.setCreationDate(new Date());
       dao.create(p);
       return p;
  }
</code></pre></li>
<li><p>Or in Main class, should I read object from database back after
creating instead of relying on return object or side effect of
createProduct method? Only thing in this case is it would add overhead of making extra call.</p>

<pre><code> public void createProduct(){
     Product p = new Product();
     productDAO.create(p);
     p = productDAO.read(p.getId());
     LOG.debug(p.getCreationDate());
  } 
</code></pre></li>
</ol>

<p>Sorry for long question. I hope I was able to explain.</p>
