Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
Android Room Allow Dao @Query to populate @Ignore columns

I'm wanting my Dao to populate @Ignore columns in my Entity class. For example:

Entity

@Entity(tableName = "example")
data class Example(
    @PrimaryKey
    val id: Long,
    val value: Int
) {
    @Ignore
    var nextId: Long = 0L
}

Dao

@Dao
interface ExampleDao {
    @Query(value = "SELECT *, (id + 1) AS nextId FROM example")
    fun getAllExamples(): List<Example>
}

However, when the application gets built, the following warning gets produced: The query returns some columns [nextId] which are not used by com.example.app.Example and it doesn't populate nextId.

Is it possible to include @Ignore columns in a @Query (if so, how)? If not, what are some strategies that can be employed to populate columns that are not present in my tables into my Entity class.

Note: I'm fully aware with the example provided that I can simply do something like:

@Ignore
val nextId: Long = id + 1

But is not the point of the question I am asking.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Based on the information that @CommonsWare has given me, the solution that I went with is

data class ExampleWithNextId(
    @Embedded
    val example: Example) {
    var nextId: Long = 0L
}

Then use it in Dao like so

@Dao
interface ExampleDao {
    @Query(value = "SELECT *, (id + 1) AS nextId FROM example")
    fun getAllExamplesWithNextId(): List<ExampleWithNextId>
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda