1

I've been banging my head against this for the past few days. I have a pretty simple Android Room setup. Here's my entity:

Entity(tableName = "some_table")
public class SomeClass {

    @PrimaryKey(autoGenerate = true)
    @NonNull
    int id;

    // Other member variables

    public SomeClass() {

    }

    public int getId(){
        return id;
    }

    public void setId(int id){
        this.id = id;
    }

}

My Dao is pretty straight-forward as well:

@Dao
public interface SomeClassDao {

    @Query("SELECT * FROM some_table")
    List<SomeClass> getAll();

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<SomeClass> someClass);

    @Update
    void update(SomeClass someClass);

    @Delete
    void delete(SomeClass someClass);

}

And nothing crazy going on with my database either:

@Database(entities = {SomeClass.class}, version = 1)
public abstract class SomeClassDatabase extends RoomDatabase {

    public static final String DATABASE_NAME = "someApp";

    public abstract SomeClassDao getDao();

}

I create my database within onCreate() of my application class:

public class SomeApp extends Application {

    private static SomeClassDatabase sDatabase;

    @Override public void onCreate() {
        super.onCreate();

        Stetho.initializeWithDefaults(this);

        sDatabase = Room.databaseBuilder(this, SomeClassDatabase.class, SomeClassDatabase.DATABASE_NAME).build();
    }

    public static ForecastDatabase getDatabase(){
        return sDatabase;
    }

}

I then insert the data into my DB using RxJava within my main activity. I don't think that portion would be a source of the problem. If so, please let me know and I'll update my post.

The issue that I'm facing is that when I inspect my database using Stetho, I have not one but two columns for my primary key. There are no other duplicate columns except for the id member variable of SomeClass - everything else is in order. Would anyone have any idea as to why this would be happening? Any insight into this would be greatly appreciated.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
coolDude
  • 647
  • 2
  • 11
  • 27
  • It seems like this is more of an issue with Stetho itself and not my project: https://stackoverflow.com/questions/34311348/stetho-showing-two-columns-with-same-name – coolDude Oct 03 '18 at 15:56
  • What are the **exact** column names in your database. It is not possible to have two columns with the same name because the database engine will not allow it. There must be some small difference in the names that you are missing. – Code-Apprentice Oct 03 '18 at 15:56
  • There's also this discussion on GitHub: https://github.com/Raizlabs/DBFlow/issues/1436 – coolDude Oct 03 '18 at 15:57
  • 1
    It was definitely something with Stetho. I downloaded the DB onto my PC and viewed it using https://sqlitebrowser.org/ and I only have a single ID column... Ughhh! So much **time wasted** on this!!! – coolDude Oct 03 '18 at 15:58
  • 1
    You can also view the database directly in Android Studio. Go to File -> Open and navigate to where you saved it. Click on the database file and click OK. Now open the Database pane which should be along the right hand side of the AS window. – Code-Apprentice Oct 03 '18 at 16:02
  • Feel free to post an answer here so that others can find the solution to the problem. – Code-Apprentice Oct 03 '18 at 16:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181235/discussion-between-cooldude-and-code-apprentice). – coolDude Oct 03 '18 at 16:15

1 Answers1

1

I was actually able to figure this out myself for the most part. The issue came down to using Stetho for viewing my DB. All of the research that I did could not explain why I had duplicate columns in my DB, especially for my primary key. Therefore, I analyzed my DB using a SQLite browser and verified that my primary key column was only showing up once. I then searched around and found others that were having similar issues with Stetho:

Stetho showing two columns with same name

https://github.com/Raizlabs/DBFlow/issues/1436

With all of that in mind, I would conclude that my DB was created correctly and that it was only an issue when using Stetho.

coolDude
  • 647
  • 2
  • 11
  • 27