Maurice
Maurice

Reputation: 2259

Room Insert Completable stop working after two or three inserts

I have a simple insertion in ROOM but for a weird reason my insertion aren't working in my app after two or three insert. There is another weird behaviour, when inserting I have a success insert but when looking in the db, there is nothing.

DAO

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(entryTable: EntryTable): Completable

ViewModel

entryRepository.saveEntryTable(EntryTable(fieldId, entryId, tabId, index))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    Timber.d("<<<<<row saved!")
                    result.value = Status.SUCCESS
                }, {
                    Timber.e(it)
                    Timber.d("<<<<<<<<<<<row not saved!")
                    result.value = Status.ERROR
                })

The OnSubscribe is always triggered, but after two inserts, nothing is present in db and I have no errors in my log.

Also there aren't any replace, because each time there is a new PK.

Edit

Here more information about this issue:

The weird thing is it's look like the Room Database is in a way copy in memory, when my app is looking for new records, I can have them, like (select * from entry_table), and show them to the user. But if I stop the app and restart it, the row are gone (since they aren't in the db)..

Upvotes: 2

Views: 110

Answers (1)

Maurice
Maurice

Reputation: 2259

I found an answer or I could say a solution to it, but for the moment I don't understand why this behaviour changed, because I didn't change anything in my app.

By changing the JournalMode from WRITE_AHEAD_LOGGING (or automatic) to TRUNCATE, all my changes are directly performed in the DB and I don't have any weird memory DB.

Upvotes: 1

Related Questions