안녕하세요 Room 데이터 중복을 방지하려고
@Insert(onConflict = OnConflictStrategy.IGNORE)
위와 같이 하고 insert를 했는데 중복이 발생하더라고요. 저 명령문이
insert 한 데이터 중 하나라도 중복이 있으면 중복 방지? 하는 건가요? 아니면 idx 를 기준으로 같은 idx 값이면 중복 방지를 하는건가요?
개발자 문서에서 답을 찾을 수 있을 것 같습니다.
OnConflict strategy constant to abort the transaction.
OnConflict strategy constant to fail the transaction.
OnConflict strategy constant to ignore the conflict.
OnConflict strategy constant to replace the old data and continue the transaction.
OnConflict strategy constant to rollback the transactio
Reference: https://developer.android.com/reference/android/arch/persistence/room/OnConflictStrategy
좀 더 부연하면, ABORT 는 트랙잭션 중 에러가 발생하면 중지하고 전부를 롤백하는 옵션이고, IGNORE은 에러를 만나도 무시하고 계속 진행하라는 옵션입니다. 대부분의 경우는 ABORT가 적절한 옵션일 것 같습니다.