Stay organized with collections
Save and categorize content based on your preferences.
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
@Retention(value = AnnotationRetention.BINARY)
public annotation Delete
Marks a method in a Dao
annotated class as a delete method.
The implementation of the method will delete its parameters from the database.
All of the parameters of the Delete method must either be classes annotated with Entity
or collections/array of it.
Example:
@Dao
public interface MusicDao {
@Delete
public fun deleteSongs(vararg songs: Song)
@Delete
public fun deleteAlbumAndSongs(album: Album, songs: List<Song>)
}
If the target entity is specified via entity
then the parameters can be of arbitrary POJO types that will be interpreted as partial entities. For example:
@Entity
data class Playlist (
@PrimaryKey
val playlistId: Long,
val ownerId: Long,
val name: String,
@ColumnInfo(defaultValue = "normal")
val category: String
)
data class OwnerIdAndCategory (
val ownerId: Long,
val category: String
)
@Dao
public interface PlaylistDao {
@Delete(entity = Playlist::class)
fun deleteByOwnerIdAndCategory(varargs idCategory: OwnerIdAndCategory)
}
Summary
Public methods
public final @NonNull KClass<@NonNull ?> getEntity()
The target entity of the delete method.
When this is declared, the delete method parameters are interpreted as partial entities when the type of the parameter differs from the target. The POJO class that represents the entity must contain a subset of the fields of the target entity. The fields value will be used to find matching entities to delete.
By default the target entity is interpreted by the method parameters.
Returns |
@NonNull KClass<@NonNull ?> |
the target entity of the delete method or none if the method should use the parameter type entities.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-13 UTC.
[null,null,["Last updated 2025-08-13 UTC."],[],[],null,["# Delete\n======\n\nArtifact: [androidx.room:room-common](/jetpack/androidx/releases/room) \n[View Source](https://cs.android.com/search?q=file:androidx/room/Delete.kt+class:androidx.room.Delete) \nAdded in [2.0.0](/jetpack/androidx/releases/room#2.0.0)\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/androidx/room/Delete \"View this page in Kotlin\") \\|Java\n\n\n```\n@Target(allowedTargets = [AnnotationTarget.FUNCTION])\n@Retention(value = AnnotationRetention.BINARY)\npublic annotation Delete\n```\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nMarks a method in a [Dao](/reference/androidx/room/Dao) annotated class as a delete method.\n\nThe implementation of the method will delete its parameters from the database.\n\nAll of the parameters of the Delete method must either be classes annotated with [Entity](/reference/androidx/room/Entity) or collections/array of it.\n\nExample: \n\n```gdscript\n@Dao\npublic interface MusicDao {\n @Delete\n public fun deleteSongs(vararg songs: Song)\n\n @Delete\n public fun deleteAlbumAndSongs(album: Album, songs: List\u003cSong\u003e)\n}\n```\n\nIf the target entity is specified via [entity](/reference/androidx/room/Delete#entity()) then the parameters can be of arbitrary POJO types that will be interpreted as partial entities. For example: \n\n```scalate-server-page\n@Entity\ndata class Playlist (\n @PrimaryKey\n val playlistId: Long,\n val ownerId: Long,\n val name: String,\n @ColumnInfo(defaultValue = \"normal\")\n val category: String\n)\n\ndata class OwnerIdAndCategory (\n val ownerId: Long,\n val category: String\n)\n\n@Dao\npublic interface PlaylistDao {\n @Delete(entity = Playlist::class)\n fun deleteByOwnerIdAndCategory(varargs idCategory: OwnerIdAndCategory)\n}\n``` \n\n| See also |\n|-------------------------------------------|---|\n| [Insert](/reference/androidx/room/Insert) | |\n| [Update](/reference/androidx/room/Update) | |\n\nSummary\n-------\n\n| ### Public constructors |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Delete](/reference/androidx/room/Delete#Delete(kotlin.reflect.KClass))`(@`[NonNull](/reference/androidx/annotation/NonNull)` `[KClass](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html)`\u003c@`[NonNull](/reference/androidx/annotation/NonNull)` ?\u003e entity)` |\n\n| ### Public methods |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|\n| `final @`[NonNull](/reference/androidx/annotation/NonNull)` `[KClass](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html)`\u003c@`[NonNull](/reference/androidx/annotation/NonNull)` ?\u003e` | [getEntity](/reference/androidx/room/Delete#getEntity())`()` The target entity of the delete method. |\n\nPublic constructors\n-------------------\n\n### Delete\n\nAdded in [2.8.0-rc01](/jetpack/androidx/releases/room#2.8.0-rc01) \n\n```\npublic Delete(@NonNull KClass\u003c@NonNull ?\u003e entity)\n``` \n\nPublic methods\n--------------\n\n### getEntity\n\n```\npublic final @NonNull KClass\u003c@NonNull ?\u003e getEntity()\n```\n\nThe target entity of the delete method.\n\nWhen this is declared, the delete method parameters are interpreted as partial entities when the type of the parameter differs from the target. The POJO class that represents the entity must contain a subset of the fields of the target entity. The fields value will be used to find matching entities to delete.\n\nBy default the target entity is interpreted by the method parameters. \n\n| Returns |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|\n| `@`[NonNull](/reference/androidx/annotation/NonNull)` `[KClass](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html)`\u003c@`[NonNull](/reference/androidx/annotation/NonNull)` ?\u003e` | the target entity of the delete method or none if the method should use the parameter type entities. |"]]