Here is the code that is not deleting...
Code:
private void delete (HibernateExUser theUser) {
try {
Session session = HibernateUtil.currentSession();
session.setFlushMode(FlushMode.AUTO);
//simply delete the retrieved user if we are deleting
session.delete(theUser);
HibernateUtil.closeSession();
} catch (Throwable e) {e.printStackTrace();}
}
Note that the session in currentSession() must be built (HibernateUtil.close() called before this method is called). Also, I have a similar method called save() that uses the exact same steps (get a new session, save user, close session) to save a new user, and that works perfectly fine. No flush() required.
This method works fine if I add a session.flush() between delete()/closeSession() calls. That's not a surprise. The default FlushMode for each session HibernateUtil returns is COMMIT. However, my save() method worked perfectly fine without resetting the flushMode of the session as I have in the code above.
In other words, session.save() seems to automatically flush, while session.delete() does not. Is this correct? Note that I am running through evaluating Hibernate and testing how it can be used, not necessarily trying to get this code to work (which would mean adding the session.flush() and be done).