1

I have a rather complicated (though not entirely unusual) scenario that seems to break with Android Room version 2.4.0 (specifically 2.4.0-beta01. It works on 2.4.0-alpha05).

I'll put the code down below, but I'll attempt to describe my situation in plain english for now.

Basically, I have two databases that reference the same table/entity. That entity is created using AutoValue, which, up until 2.4.0-alpha05, worked fine with the @AutoValue.CopyAnnotations annotation. However, once I upgraded to 2.4.0-beta01, the song table name is no longer detected:

There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: word_table)

Without further ado, here is same sample code (adapted from the developer notes)

@AutoValue
@Entity(tableName = "word_table")
public abstract class Word {

  @AutoValue.CopyAnnotations
  @PrimaryKey
  @NonNull
  @ColumnInfo(name = "word")
  public abstract String word();

  @NonNull
  public static Word create(@NonNull String word) {
      return new AutoValue_Word.Builder().word(word).build();
  }

  @AutoValue.Builder
  public abstract static class Builder {
      abstract Builder word(String word);
      public abstract Word build();
  }
}

@Dao
@TypeConverters(Converters.class)
public interface WordDao {

    @Query("SELECT * FROM word_table")
    LiveData<List<Word>> getAlphabetizedWords();
}

@Dao
@TypeConverters(Converters.class)
public interface WordDao2 {

    @Query("SELECT * FROM word_table")
    LiveData<List<Word>> getAlphabetizedWords();
}

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

  public abstract WordDao wordDao();

  public static WordRoomDatabase createDatabase(final Context context) {
      return Room.databaseBuilder(context.getApplicationContext(), WordRoomDatabase.class, "word_database").build();
  }
}

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

    public abstract WordDao2 wordDao2();

    public static WordRoomDatabase2 createDatabase(final Context context) {
        return Room.databaseBuilder(context.getApplicationContext(), WordRoomDatabase2.class, "word_database").build();
   }
}

Update: When I look at the generated schema, only WordRoomDatabase1 is populated, though pretty messed up:

{
  "formatVersion": 1,
  "database": {
    "version": 1,
    "identityHash": "a67e5757cf2fc0be1d7cee0b7192312f",
    "entities": [
      {
        "tableName": "word_table",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` ()",
        "fields": [],
        "primaryKey": {
          "columnNames": [],
          "autoGenerate": false
        },
        "indices": [],
        "foreignKeys": []
      }
    ],
    "views": [],
    "setupQueries": [
      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'a67e5757cf2fc0be1d7cee0b7192312f')"
    ]
  }
}

Update 2: I you change Word.java to not use AutoValue, it works great:

@Entity(tableName = "word_table")
public class Word {

    @PrimaryKey
    @NonNull
    @ColumnInfo(name = "word")
    private String word;

    public Word(@NonNull String word) {this.word = word;}

    public String getWord(){return this.word;}
}
skywalkerdude
  • 117
  • 1
  • 8
  • Why have two databases reference the same entity, you ask? I don't want to put my debug data functions inside of my release DAO, so I create a debug database + DAO that also references the same underlying sqlite table. – skywalkerdude Dec 25 '21 at 04:19

0 Answers0