2 composition OneToOne to the same entity

How can I implement two composition relations between two entities.

I have two entities, Inspection and InspectionDecision.
Inspection have 2 decisions, the agent decision and the manager decision.
A decision don’t exist alone so it’s a composition with Inspection.

I try this implementation but the reverse composition is not possible (Decision → Inspection) !
I have to select a mappedBy field but I have two fields…

@JmixEntity
@Table(name = "INSPECTION", indexes = [
    Index(name = "IDX_INSPECTION_AGENT_DECISION", columnList = "AGENT_DECISION_ID"),
    Index(name = "IDX_INSPECTION_MANAGER_DECISION", columnList = "MANAGER_DECISION_ID")
])
@Entity
open class Inspection {
    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    var id: UUID? = null

    @JoinColumn(name = "AGENT_DECISION_ID")
    @Composition
    @OneToOne(fetch = FetchType.LAZY)
    var agentDecision: InspectionDecision? = null

    @JoinColumn(name = "MANAGER_DECISION_ID")
    @Composition
    @OneToOne(fetch = FetchType.LAZY)
    var managerDecision: InspectionDecision? = null
    
    …
}
@JmixEntity
@Table(name = "INSPECTION_DECISION")
@Entity
open class InspectionDecision {
    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    var id: UUID? = null

    @Composition
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "???")
    var inspection: Inspection? = null
    
    …
}

Is there a solution to have a reverse composition with this implementation ?
Do I need to remove the 2 OneToOne and set a OneToMany ?

The reference from InspectionDecision.inspection is not needed for Jmix UI to work, you can drop it. And anyway marking it @Composition is incorrect, this annotation must be on the aggregate root only.

Ok, I understand that the reverse relation is not mandatory for main function of Jmix,
but why I can’t create it correctly as a composition which could be useful to have it in some case (for example in a browse screen on InspectionDecision with a condition on Inspection)…

In fact you can, but it will be 2 different reverse attributes:

@JmixEntity
@Table(name = "INSPECTION_DECISION")
@Entity
open class InspectionDecision {
    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    var id: UUID? = null

    @Composition
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "agentDecision")
    var agentInspection: Inspection? = null
    
    @Composition
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "managerDecision")
    var managerInspection: Inspection? = null
    …
}

Yes, I can do that, good idea…