Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

344
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!