The flushMode property of the Hibernate session

https://blog.csdn.net/looyo/article/details/6309136

The cleaning cache here can be understood as hibernate automatically executes a session.flush();

What kind of flush mode to choose is to adopt what kind of data refresh strategy for hibernate session. Session.setFlushMode() is used to set the time point for clearing the cache.
Compare several flush modes:
FlushMode.AUTO: When calling the query method of Session, clear the cache. Note: This rule must ensure that in an explicitly opened transaction, when calling Session.commit() for outside a transaction, clear the cache call When Session.flush(), clear the cache
FlushMode.COMMIT: When calling the query method of the Session, when calling Session.commit() without clearing the cache, when calling Session.flush() to clear the cache, clear the cache
FlushMode.NEVER(MANUAL): When calling the query method of Session, when calling Session.commit() without clearing the cache, when calling Session.flush() without clearing the cache, clearing the cache

 

FlushMode.ALWAYS: The test found no difference between auto and auto.

 When calling the query method of Session, clear the cache. Note: This rule must ensure that in an explicitly opened transaction, when calling Session.commit() for outside a transaction, clearing the cache when calling Session.flush(), clearing the cache

=================

The three cases synchronize the database session.flushmode=manual at the following times: 1. Only manually call flush()

session.flushmode=commit 1. Manually call flush() 2. When commit()

session.flushmode=auto 1. Manually call flush() 2. Commit() time 3. Before query (tested (oracle driver), it must be within the transaction, not sure if it is all the case)

==================

 

For comparison, please note that FlushMode.NEVER If you do not clear the cache before calling the query method of Session, then dirty data will be introduced, so there will be that step session.flush(); // who know's what been done till now in FlushMode. Before NEVER, clear the cache to ensure that the data is correct.
In the last program in the text: Put FlushMode.NEVER between two session.flush() to ensure data consistency without clearing the cache

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325950669&siteId=291194637