title: Hibernate Session saveOrUpdate does not update
body: <p>I am using hibernate with derby. I use the following pattern to save my objects:</p>
  
  <pre><code>Session session = null
  Transaction tx = null;
  try {
      session = mySessionFactory.openSession();
      tx = session.beginTransaction();
      MyPersistentType obj = session.load(MyPersistentType.class, id);
      obj.setAttribute(attr);
      session.saveOrUpdate(obj);
      tx.commit();
      log.debug("Committed");
  } catch (Exception e) {
      if (tx != null) tx.rollback();
  } finally {
      if (session != null) session.close();
  }
  </code></pre>
  
  <p>In the above, I am certain flushMode is AUTO, my log statement prints, and the logs show that JDBC connection have been committed, with the new attribute I have set to my object. However the next time I fetch the object from the DB (and it happens split second later), the object being fetched has the original value, not the newly set one.</p>
  
  <p>About my MyPersistentType:</p>
  
  <ul>
  <li>It has an auto generated Long id</li>
  <li>It does not have version number, all updates to it are encapsulated within a transaction</li>
  <li>It is annotated. I do not use mapping, I use annotations.</li>
  </ul>
  
  <p>All I can think of is that some caching has gone awry, except I do not even use any cache. Saving the object for the first time (using a different session object, in the same manner as above) works fine. It is the updates that I am having problem with. BTW, I did try session.flush() (no good reason really, just for completeness), session.merge() (even though the object is attached) etc. None worked. So, my question(s) are:</p>
  
  <ul>
  <li>Could it still be some caching problem?</li>
  <li>If so can I force this query to hit the disk each time</li>
  </ul>
  
  <p>Or if anything else you can think of. I am completely stumped.</p>
  
  <p>Edit1: After the above sequence gets executed, I stopped the service and connected to the DB using IJ. Doing select on the said table, I saw that the table was not modified, even though the commit did not fail. Also, the log shows the following lines:</p>
  
  <pre><code>org.hibernate.event.internal.AbstractFlushingEventListener  - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
  org.hibernate.event.internal.AbstractFlushingEventListener  - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
  </code></pre>
  
  <p>In other words, the commit did succeed, but the session did not realize the object was modified. So the question becomes, how can I tell the session that there is a dirty object in it. I thought this should be automatic, but clearly it is not happening in this case.</p>
  
  <p>Thanks in advance.</p>