Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

345
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda