code: protected FlushMode applyFlushMode(Session session, boolean existingTransaction) {
          if(isApplyFlushModeOnlyToNonExistingTransactions() && existingTransaction) {
              return null;
          }
  
          if (getFlushMode() == FLUSH_NEVER) {
              if (existingTransaction) {
                  FlushMode previousFlushMode = session.getHibernateFlushMode();
                  if (!previousFlushMode.lessThan(FlushMode.COMMIT)) {
                      session.setHibernateFlushMode(FlushMode.MANUAL);
                      return previousFlushMode;
                  }
              } else {
                  session.setHibernateFlushMode(FlushMode.MANUAL);
              }
          } else if (getFlushMode() == FLUSH_EAGER) {
              if (existingTransaction) {
                  FlushMode previousFlushMode = session.getHibernateFlushMode();
                  if (!previousFlushMode.equals(FlushMode.AUTO)) {
                      session.setHibernateFlushMode(FlushMode.AUTO);
                      return previousFlushMode;
                  }
              } else {
                  // rely on default FlushMode.AUTO
              }
          } else if (getFlushMode() == FLUSH_COMMIT) {
              if (existingTransaction) {
                  FlushMode previousFlushMode = session.getHibernateFlushMode();
                  if (previousFlushMode.equals(FlushMode.AUTO) || previousFlushMode.equals(FlushMode.ALWAYS)) {
                      session.setHibernateFlushMode(FlushMode.COMMIT);
                      return previousFlushMode;
                  }
              } else {
                  session.setHibernateFlushMode(FlushMode.COMMIT);
              }
          } else if (getFlushMode() == FLUSH_ALWAYS) {
              if (existingTransaction) {
                  FlushMode previousFlushMode = session.getHibernateFlushMode();
                  if (!previousFlushMode.equals(FlushMode.ALWAYS)) {
                      session.setHibernateFlushMode(FlushMode.ALWAYS);
                      return previousFlushMode;
                  }
              } else {
                  session.setHibernateFlushMode(FlushMode.ALWAYS);
              }
          }
          return null;
      }
docs: Apply the flush mode that's been specified for this accessor to the given Session.
  
  @param session             the current Hibernate Session
  @param existingTransaction if executing within an existing transaction
  @return the previous flush mode to restore after the operation, or <code>null</code> if none
  @see #setFlushMode
  @see org.hibernate.Session#setFlushMode