title: Hibernate will not persist data after save
body: <p>Can someone explain why the "lastAccessed" date does not get saved to the database in this example and how I can get it to save to the DB?  My understanding is that the do object is an attached object after the save() call and therefore all modifications should be persisted automatically.</p>
  
  <p>Note: "myDate" is persisted correctly, so all other spring configuration seems to be correct.</p>
  
  <pre><code>@Transactional(readOnly = false)
  public DateObject getOrCreateDateObject(Date myDate) {
      DateObject do = null;
  
      do = getCurrentDateObject();  // For my tests, this has been returning null
  
      if (do == null) {
          // create a new object
          do = new DateObject();
          do.setDate(myDate);
          sessionFactory.getCurrentSession().save(do);
      }
  
      // This does not persist to the database
      do.setLastAccessed(new Date());
  
      return do;
  }
  </code></pre>
  
  <p>I have also tried some of the following combinations (and more) after the save() call.  None of these work:</p>
  
  <pre><code>sessionFactory.getCurrentSession().merge(do);  // tried before and after do.setDate(d2)
  
  sessionFactory.getCurrentSession().update(do);
  
  sessionFactory.getCurrentSession().saveOrUpdate(do);
  
  sessionFactory.getCurrentSession().flush();
  
  DateObject doCopy = (DateObject)sessionFactory.getCurrentSession().load(DateObject.class, do.getId());
  sessionFactory.getCurrentSession().merge(doCopy);
  doCopy.setLastAccessed(new Date());
  </code></pre>
  
  <p>I'm hoping this is an easy answer that I'm just not seeing.  Thank you for your help!</p>
  
  <p>Edit #1 05/22/2012</p>
  
  <p>As requested, here is the mapping for this entity, specified in src/main/resources/META-INF/dateobject.hbm.xml.  I can see that the columns are created in the database using "SELECT * FROM dateObjects" in the mysql client.  MY_DATE is populated correctly, but LAST_ACCESSED is set to NULL.</p>
  
  <pre><code>&lt;class name="com.example.entity.DateObject" table="dateObjects"&gt;
      &lt;id name="id" column="DATE_OBJECT_ID"&gt;
          &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="date" type="date" column="MY_DATE" /&gt;
      &lt;property name="lastAccessed" type="date" column="LAST_ACCESSED" /&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>Edit #2 05/24/2012</p>
  
  <p>I have a working SSCCE at <a href="https://github.com/eschmidt/dateobject" rel="noreferrer">https://github.com/eschmidt/dateobject</a>.  The interesting thing is that the web client (calling localhost:8080/view/test) shows that lastAccessed is set correctly, but when I check the database with the MySQL client, it shows that lastAccessed is NULL.  With this complete set of code, can anybody see why the database wouldn't update even though the method is marked @Transactional?</p>