2

I am trying to run a select query on Room. I have the following Dao:

@Dao
abstract class TopicDao {
    @Query("SELECT * FROM Topic WHERE Id = :topicId")
    abstract fun getTopicModel(topicId: String): LiveData<TopicUiModel>
}

the following Entity:

@Entity
data class Topic(
    @PrimaryKey
    val Id: String,
    val Name: String,
)

and the following data model:

data class TopicUiModel(
    val Id: String,
    val Name: String,
    val Selected: Boolean,
)

However I am getting the following error:

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

The error makes sense but how do I make room to ignore this field?

M. Azyoksul
  • 1,580
  • 2
  • 16
  • 43
  • Does this answer your question? [Android Room: @Ignore vs Transient](https://stackoverflow.com/questions/47718206/android-room-ignore-vs-transient) – Mohammad Tauqir Apr 26 '21 at 16:18
  • Using @ Ignore or @ Transient gives the followign error: "Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type)." – M. Azyoksul Apr 26 '21 at 16:21
  • 1
    did you try this https://stackoverflow.com/questions/44485631/room-persistence-errorentities-and-pojos-must-have-a-usable-public-constructor – Mohammad Tauqir Apr 26 '21 at 16:22
  • Instead of this, `LiveData` change return type to `LiveData` – Varsha Kulkarni Apr 26 '21 at 16:31
  • @VarshaKulkarni In this case it seems trivial, however, the actual model is more complicated than I showed here. Your solution corresponds to creating a separate and extremely similar data class for every single model I have and use MutableLiveData to cast between them. Just for this one flag, I didn't want to go down that path. – M. Azyoksul Apr 26 '21 at 16:39

0 Answers0