@Transactional
  public ClusterEntity merge(ClusterEntity clusterEntity, boolean flush) {
    EntityManager entityManager = entityManagerProvider.get();
    clusterEntity = entityManager.merge(clusterEntity);

    // force any queued persist/merges to be written to the database, including
    // the merge from above
    if (flush) {
      entityManager.flush();
    }

    return clusterEntity;
  }
Merge the specified entity into the current persistence context, optionally
instructing the {@link EntityManager} to write any queued persist/merges
into the database immediately.

@param clusterEntity
         the entity to merge (not {@code null}).
@param flush
         if {@code true} then {@link EntityManager#flush()} will be invoked
         immediately after the merge.
@return the managed entity which was merged (never {@code null}).
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java