What Should You Use with Room?

@Insert(onConflict = OnConflictStrategy.REPLACE) may have its uses, particularly for cases where you are trying to use non-generated primary keys (e.g., “natural” keys).

Beyond that, ABORT, FAIL, and ROLLBACK all have the effect in Room of rolling back your requested insert or update. The first two throw a SQLiteConstraintException, which is a better exception than the SQLiteException that you get from ROLLBACK. And, since ABORT happens to be the default strategy, sticking with the default may well be your best option.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.