code: private void flush()
      {
          // Get flush stack from Flush Manager
          Deque<Node> fs = flushManager.getFlushStack();
  
          // Flush each node in flush stack from top to bottom unit it's empty
  
          if (log.isDebugEnabled())
          {
              log.debug("Flushing following flush stack to database(s) (showing stack objects from top to bottom):\n"
                      + fs);
          }
          if (fs != null)
          {
              boolean isBatch = false;
              while (!fs.isEmpty())
              {
                  Node node = fs.pop();
  
                  // Only nodes in Managed and Removed state are flushed, rest
                  // are ignored
                  if (node.isInState(ManagedState.class) || node.isInState(RemovedState.class))
                  {
                      EntityMetadata metadata = getMetadata(node.getDataClass());
                      node.setClient(getClient(metadata));
  
                      // if batch size is defined.
                      if ((node.getClient() instanceof Batcher) && ((Batcher) (node.getClient())).getBatchSize() > 0)
                      {
                          isBatch = true;
                          ((Batcher) (node.getClient())).addBatch(node);
                      }
                      else if (isTransactionInProgress
                              && MetadataUtils
                                      .defaultTransactionSupported(metadata.getPersistenceUnit(), kunderaMetadata))
                      {
                          onSynchronization(node, metadata);
                      }
                      else
                      {
                          node.flush();
                      }
                  }
  
              }
  
              if (!isBatch)
              {
                  // TODO : This needs to be look for different
                  // permutation/combination
                  // Flush Join Table data into database
                  flushJoinTableData();
                  // performed,
              }
          }
      }
docs: Flushes Dirty objects in {@link PersistenceCache} to databases.