Android- Room (Cannot rollback - no transaction is active) when deleting records

Viewed 747

I want to delete each time the whole table Employees. The table consists of 1 million records(100mb). When I execute the code below I get the message below and a low disk storage in emulator. I increased the storage and run it again but after a while throws the same error and again low storage. It seems that it takes all the device storage for some reason.

android.database.sqlite.SQLiteException: cannot rollback - no transaction is active (code 1) at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method) at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:555) at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:439) at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401) at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522) at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.endTransaction(FrameworkSQLiteDatabase.java:90) at android.arch.persistence.room.RoomDatabase.endTransaction(RoomDatabase.java:261) at com.ehr.Database.Daos.EmployeeDao_Impl.deleteEmployees(EmployeeDao_Impl.java:175) at com.ehr.DataRepository$7.run(DataRepository.java:450) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)

Very important notes

  1. If records decreased to 25k,deletion works fine.
  2. If I remove the code with the live data and observer, deletion works fine with 1 million records.
  3. If I put a different live data and observer, that observes to a different table other than Employee, deletion works fine.
  4. In API 27 runs well. Although It takes some time to delete. APIS 19,21,23 not working.

Any ideas? Is this a bug?

Code

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((BasicApp) getApplication()).getRepository().getNotifyEmployee().observe(this,new Observer<Integer>() {

                @Override
                public void onChanged(@Nullable Integer number) {
                    //staff
                }
});


  executors.diskIO().execute(new Runnable() {
    @Override
    public void run() {
        mDatabase.repoEmployee().deleteEmployees();
     });
  }  

} 

Dao

  @Dao
  public interface EmployeeDao {

    @Query("DELETE FROM Employee")
    void deleteEmployees();

     @Transaction @Query("SELECT COUNT(*)  FROM Employee")
     LiveData<Integer> getNotifyEmployee();
  }       
0 Answers
Related