English | 简体中文

api-docs / org.ktorm.entity / Entity / flushChanges

flushChanges

abstract fun flushChanges(): Int (source code)

Update the property changes of this entity into the database and return the affected record number.

Using this function, we need to note that:

  1. This function requires a primary key specified in the table object via Table.primaryKey,
    otherwise Ktorm doesn’t know how to identify entity objects and will throw an exception.
  2. The entity object calling this function must be ATTACHED to the database first. In Ktorm’s implementation, every entity object holds a reference fromDatabase. For entity objects obtained by sequence APIs, their fromDatabase references point to the database they are obtained from. For entity objects created by Entity.create or Entity.Factory, their fromDatabase references are null initially, so we can not call flushChanges on them. But once we use them with add or update function, fromDatabase will be modified to the current database, so we will be able to call flushChanges on them afterwards.

See Also

add

update