merge(entity) {
    if (!(entity instanceof AbstractEntity)) {
      throw new TypeError("The entity must an AbstractEntity instance")
    }
    var entityClass = entity.constructor
    validateEntityClass(entityClass)

    if (!this[PRIVATE.activeTransaction]) {
      throw new Error("There is no transaction active on this entity " +
          "manager, merging an entity into the persistence context would " +
          "not have any effect.")
    }

    if (this.contains(entity)) {
      return entity // nothing to do
    }

    if (!this[PRIVATE.entityKeyPaths].size) {
      throw new Error("It appears that you have attempted to merge an " +
          "entity into the persistence context before the entity manager " +
          "has loaded the key paths of the object stores, therefore the " +
          `primary key of the provided entity (${entity}) cannot be ` +
          "determined. In order to prevent this error from happening, it is " +
          "recommended to run transactions that merge entities into the " +
          "persistence context using the runTransaction() method instead.")
    }

    if (!this[PRIVATE.entityKeyPaths].has(entityClass.objectStore)) {
      throw new Error(`The object store (${entityClass.objectStore}) of the ` +
          "provided entity does not exist")
    }

    let keyPath = this[PRIVATE.entityKeyPaths].get(entityClass.objectStore)
    let primaryKey = getPrimaryKey(entity, keyPath)

    if (!this.containsByPrimaryKey(entityClass, primaryKey)) {
      return this[PRIVATE.manage](entityClass, keyPath, entity, true)
    }

    let entityClone = clone(entity)
    let managedEntity = this[PRIVATE.manage](
      entityClass,
      keyPath,
      entityClone // prevent conflict in persistence context
    )
    Object.assign(managedEntity, entityClone)

    return managedEntity
  }
/**
   * Merges the state of the provided entity into the persistence context of
   * this entity manager.
   *
   * This method can be used only within a transaction because merging an
   * entity into the persistence context would have no effect outside a
   * transaction.
   *
   * Note that if you attempt to use this method within a transaction started
   * using the {@codelink startTransaction()} method instead of the
   * {@codelink runTransaction()} method, especially while initializing the
   * {@codelink EntityManagerFactory} with a database connection promise, this
   * method may throw an error because the key paths of the database's object
   * stores may not be loaded yet.
   *
   * @template {T} extends AbstractEntity
   * @param {T} entity The entity to merge into the persistence context.
   * @return {T} An entity managed by this entity manager, with its state set
   *         to a clone of the provided entity.
   */
Merges the state of the provided entity into the persistence context of
this entity manager.

This method can be used only within a transaction because merging an
entity into the persistence context would have no effect outside a
transaction.

Note that if you attempt to use this method within a transaction started
using the  startTransaction() method instead of the
runTransaction() method, especially while initializing the
EntityManagerFactory with a database connection promise, this
method may throw an error because the key paths of the database's object
stores may not be loaded yet.

@template {T} extends AbstractEntity
@param {T} entity The entity to merge into the persistence context.
@return {T} An entity managed by this entity manager, with its state set
to a clone of the provided entity.
Merges the state of the provided entity into the persistence context of this entity manager . This method can be used only within a transaction because merging an entity into the persistence context would have no effect outside a transaction . Note that if you attempt to use this method within a transaction started using the startTransaction () method instead of the runTransaction () method especially while initializing the EntityManagerFactory with a database connection promise this method may throw an error because the key paths of the database ' s object stores may not be loaded yet . @template { T } extends AbstractEntity @param { T } entity The entity to merge into the persistence context . @return { T } An entity managed by this entity manager with its state set to a clone of the provided entity .
merge(entity) {
    if (!(entity instanceof AbstractEntity)) {
      throw new TypeError("The entity must an AbstractEntity instance")
    }
    var entityClass = entity.constructor
    validateEntityClass(entityClass)
    if (!this[PRIVATE.activeTransaction]) {
      throw new Error("There is no transaction active on this entity " +
          "manager, merging an entity into the persistence context would " +
          "not have any effect.")
    }
    if (this.contains(entity)) {
      return entity 
    }
    if (!this[PRIVATE.entityKeyPaths].size) {
      throw new Error("It appears that you have attempted to merge an " +
          "entity into the persistence context before the entity manager " +
          "has loaded the key paths of the object stores, therefore the " +
          `primary key of the provided entity (${entity}) cannot be ` +
          "determined. In order to prevent this error from happening, it is " +
          "recommended to run transactions that merge entities into the " +
          "persistence context using the runTransaction() method instead.")
    }
    if (!this[PRIVATE.entityKeyPaths].has(entityClass.objectStore)) {
      throw new Error(`The object store (${entityClass.objectStore}) of the ` +
          "provided entity does not exist")
    }
    let keyPath = this[PRIVATE.entityKeyPaths].get(entityClass.objectStore)
    let primaryKey = getPrimaryKey(entity, keyPath)
    if (!this.containsByPrimaryKey(entityClass, primaryKey)) {
      return this[PRIVATE.manage](entityClass, keyPath, entity, true)
    }
    let entityClone = clone(entity)
    let managedEntity = this[PRIVATE.manage](
      entityClass,
      keyPath,
      entityClone 
    )
    Object.assign(managedEntity, entityClone)
    return managedEntity
  }
merge ( entity ) { if ( ! ( entity instanceof AbstractEntity ) ) { throw new TypeError ( "The entity must an AbstractEntity instance" ) } var entityClass = entity . constructor validateEntityClass ( entityClass ) if ( ! this [ PRIVATE . activeTransaction ] ) { throw new Error ( "There is no transaction active on this entity " + "manager, merging an entity into the persistence context would " + "not have any effect." ) } if ( this . contains ( entity ) ) { return entity } if ( ! this [ PRIVATE . entityKeyPaths ] . size ) { throw new Error ( "It appears that you have attempted to merge an " + "entity into the persistence context before the entity manager " + "has loaded the key paths of the object stores, therefore the " + ` ${ entity } ` + "determined. In order to prevent this error from happening, it is " + "recommended to run transactions that merge entities into the " + "persistence context using the runTransaction() method instead." ) } if ( ! this [ PRIVATE . entityKeyPaths ] . has ( entityClass . objectStore ) ) { throw new Error ( ` ${ entityClass . objectStore } ` + "provided entity does not exist" ) } let keyPath = this [ PRIVATE . entityKeyPaths ] . get ( entityClass . objectStore ) let primaryKey = getPrimaryKey ( entity , keyPath ) if ( ! this . containsByPrimaryKey ( entityClass , primaryKey ) ) { return this [ PRIVATE . manage ] ( entityClass , keyPath , entity , true ) } let entityClone = clone ( entity ) let managedEntity = this [ PRIVATE . manage ] ( entityClass , keyPath , entityClone ) Object . assign ( managedEntity , entityClone ) return managedEntity }
Merges the state of the provided entity into the persistence context of
 this entity manager.
Merges the state of the provided entity into the persistence context of this entity manager .
// nothing to do // prevent conflict in persistence context