I would like to link 2 entities but using a column that is not a primary key (and not marked with @Id in the class file).
@Entity
class MediaLog(
@Id
var id: UUID = UUID.randomUUID()
var caseSystemId: String,
var articleSummary: String?,
var totalArticleCount: Int,
var resolvedAt: Instant? = null,
var lastCheckPerformedAt: Instant? = null
)
@Entity
@Audited
class CustomerCase(
@Id
var id: UUID = UUID.randomUUID()
var authAccountId: UUID,
@Enumerated(EnumType.STRING)
var status: CaseStatus,
var caseSystemId: String? = null
)
The relationship is OneToOne and they should be linked using the caseSystemId. The MediaLog MUST have a valid CustomerCase to link to it, but a there might be situations where some CustomerCase doesn't have any MediaLog entries. And yes, the MediaLog is not audited while the CustomerCase is audited (but that's not a problem).
I've tried all the possible combications of using @OneToOne and @JoinColumn, and playing with properties of each annotation but can't get it to work. Any ideas?