If FlushMode.AUTO is set, will Hibernate flush my updated persistent object when I call session.close()?
I know that session.close() does not normally flush the session but I'm not sure how FlushMode.AUTO affects this.
From the Docs:
FlushMode.AUTO
The Session is sometimes flushed before query execution in order to ensure that queries never return stale state. This is the default flush mode.
Does this mean I can rely on Hibernate to verify my changes are flushed sometimes before my session is closed?
Small code example:
Session session = HibernateSessionFactory.getSession();
PersistedObject p = session.get(PersistedObject.class,id);
p.setSomeProperty(newValue);
session.close();
UPDATE
According to the docs these are the places where the session will flush (when AUTO is used)
- before some query executions
- from org.hibernate.Transaction.commit()
- from Session.flush()
This does not say anything about Session.close()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…