# OnConflictStrategy

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

*** ** * ** ***


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

<br />

*** ** * ** ***

Set of conflict handling strategies for various {@link Dao} methods.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/room/OnConflictStrategy#ABORT() = 3` OnConflict strategy constant to abort the transaction. |
| `static final int` | `https://developer.android.com/reference/androidx/room/OnConflictStrategy#FAIL() = 4` **This field is deprecated.** Use ABORT instead. |
| `static final int` | `https://developer.android.com/reference/androidx/room/OnConflictStrategy#IGNORE() = 5` OnConflict strategy constant to ignore the conflict. |
| `static final int` | `https://developer.android.com/reference/androidx/room/OnConflictStrategy#NONE() = 0` OnConflict strategy constant used by default when no other strategy is set. |
| `static final int` | `https://developer.android.com/reference/androidx/room/OnConflictStrategy#REPLACE() = 1` OnConflict strategy constant to replace the old data and continue the transaction. |
| `static final int` | `https://developer.android.com/reference/androidx/room/OnConflictStrategy#ROLLBACK() = 2` **This field is deprecated.** Use ABORT instead. |

## Constants

### ABORT

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
public static final int ABORT = 3
```

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

### FAIL

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0) Deprecated in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
public static final int FAIL = 4
```

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

OnConflict strategy constant to fail the transaction.

Does not work as expected. The transaction is rolled back. Use `https://developer.android.com/reference/androidx/room/OnConflictStrategy#ABORT()`.

### IGNORE

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
public static final int IGNORE = 5
```

OnConflict strategy constant to ignore the conflict.

An `https://developer.android.com/reference/androidx/room/Insert` DAO method 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

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
public static final int NONE = 0
```

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/androidx/room/OnConflictStrategy#ABORT()` strategy is applied. *The transaction is rolled back.*

### REPLACE

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
public static final int REPLACE = 1
```

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

An `https://developer.android.com/reference/androidx/room/Insert` DAO method 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

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0) Deprecated in [2.5.0](https://developer.android.com/jetpack/androidx/releases/room#2.5.0)

```
public static final int ROLLBACK = 2
```

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

OnConflict strategy constant to rollback the transaction.

Does not work with Android's current SQLite bindings. Use `https://developer.android.com/reference/androidx/room/OnConflictStrategy#ABORT()` to roll back the transaction.