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

357
Visualizações
Room @Relation using a composite index

Context

Hello, I'm working with 2 tables related by a foreign key, WorkOrderItemUsage and WorkOrderItemUsageLot. Every workOrderItemUsage can have multiple lots, so it's a 1 to n relationship, to make my work easier I'm implementing a helper entity called WorkOrderItemUsageWithLots, it's used to retrieve all the data from both tables in one go using room @Relation.

Problem

I've tried to use @Relation with a single column and it works correctly, but I need to stablish my relation based on a composite key like the foreign key, I understand there's no support for composite keys using @Relation I'm trying to link it using an index, Am I missing something? Do I have to refuse to use @Relation in favor of good ol SQL joins in queries?

  • error: Cannot find the parent entity column woItemUsagePk in WorkOrderItemUsageWithLots
  • Error prints the available columns for @Relation
  • Options: woIdItemUsage, itemId, itemNumber, itemThirdNumber, itemDescription, quantityMeasure, branchId, branchDescription, locationId, doseQuantity, doseMeasureUnit, itemAction, itemPlague, itemJustification private java.util.List lotList

    @Entity(
    primaryKeys = ["itemId", "branchId", "woIdItemUsage"],
    foreignKeys = [
        ForeignKey(entity = WorkOrder::class,
                parentColumns = ["woId"],
                childColumns = ["woIdItemUsage"],
                onUpdate = ForeignKey.CASCADE,
                onDelete = ForeignKey.CASCADE)],
    indices = [Index("woIdItemUsage", "itemId", "branchId", name = "woItemUsagePk", unique = true)]
    
    @Entity(
            primaryKeys = ["woIdItemUsageLot", "itemId", "branchId", "lotId"],
            foreignKeys = [
                ForeignKey(entity = WorkOrderItemUsage::class,
                        parentColumns = ["woIdItemUsage", "itemId", "branchId"], 
                        childColumns = ["woIdItemUsageLot", "itemId", "branchId"],
                        onUpdate = ForeignKey.CASCADE,
                        onDelete = ForeignKey.CASCADE)],
            indices = [Index("woIdItemUsageLot", "itemId", "branchId", name = "woItemUsageLotPk", unique = true)])
    
    
    
    
    class WorkOrderItemUsageWithLots(@Embedded var itemUsage: WorkOrderItemUsage) {
    
    @Relation(parentColumn = "woItemUsagePk", entityColumn= "woItemUsageLotPk")
    var lotList: List<WorkOrderItemUsageLot> = emptyList()}
    
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You don't have a woItemUsagePk field declared in your entity class. You must declare a field to hold the value, Room will not dynamically declare it for you.

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