# OnConflictStrategy

Artifact: [androidx.room3:room3-common](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/OnConflictStrategy.kt+class:androidx.room3.OnConflictStrategy) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  @Retention(value = AnnotationRetention.BINARY)
  @IntDef(value = [0, 1, 2, 3, 4, 5])
  annotation OnConflictStrategy
  ```

*** ** * ** ***

Set of conflict handling strategies for various `https://developer.android.com/reference/kotlin/androidx/room3/Dao` functions.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/Insert#onConflict()` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/Update#onConflict()` |   |

## Summary

| ### Constants |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#ABORT() = 3` OnConflict strategy constant to abort the transaction. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#FAIL() = 4` **This property is deprecated.** Use ABORT instead. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#IGNORE() = 5` OnConflict strategy constant to ignore the conflict. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#NONE() = 0` OnConflict strategy constant used by default when no other strategy is set. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#REPLACE() = 1` OnConflict strategy constant to replace the old data and continue the transaction. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#ROLLBACK() = 2` **This property is deprecated.** Use ABORT instead. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#OnConflictStrategy()()` | Cmn |

## Constants

### ABORT

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
const val ABORT = 3: Int
```

OnConflict strategy constant to abort the transaction. *The transaction is rolled back.*

### FAIL

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0) Deprecated in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
const val FAIL = 4: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Use ABORT instead.

OnConflict strategy constant to fail the transaction.

The behavior of this strategy is based on the `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteDriver` implementation provided to Room, For example, it does not work with Android's current SQLite bindings, instead use `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#ABORT()` to roll back the transaction.

### IGNORE

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
const val IGNORE = 5: Int
```

OnConflict strategy constant to ignore the conflict.

An `https://developer.android.com/reference/kotlin/androidx/room3/Insert` DAO function that returns the inserted rows ids will return `-1` for rows that are not inserted since this strategy will ignore the row if there is a conflict.

### NONE

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
const val NONE = 0: Int
```

OnConflict strategy constant used by default when no other strategy is set. Using it prevents Room from generating `ON CONFLICT` clause. It may be useful when there is a need to use `ON CONFLICT` clause within a trigger. The runtime behavior is the same as when `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#ABORT()` strategy is applied. *The transaction is rolled back.*

### REPLACE

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
const val REPLACE = 1: Int
```

OnConflict strategy constant to replace the old data and continue the transaction.

An `https://developer.android.com/reference/kotlin/androidx/room3/Insert` DAO function that returns the inserted rows ids will never return `-1` since this strategy will always insert a row even if there is a conflict.

### ROLLBACK

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0) Deprecated in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
const val ROLLBACK = 2: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Use ABORT instead.

OnConflict strategy constant to rollback the transaction.

The behavior of this strategy is based on the `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteDriver` implementation provided to Room, For example, it does not work with Android's current SQLite bindings, instead use `https://developer.android.com/reference/kotlin/androidx/room3/OnConflictStrategy#ABORT()` to roll back the transaction.

## Public constructors

### OnConflictStrategy

Cmn

```
OnConflictStrategy()
```