xenoterracide
xenoterracide

Reputation: 16865

Optional unidirectional one to one relationship with compound key

I have 3 tables

-----
|foo
-----
| id pk
| rfid unique
-----
|bar
-----
|id pk
|a
|compound
|key
-----------------------------
| unique ( a, compound, key )
------------
|foo_bar_baz
------------
|id pk
|rfid
|a
|compound
|key
|baz

I'd like to make a FooBarBaz relationship entity that looks something like (written in kotlin)

data class FooBarBaz(
     @OneToOne
     @JoinColumn(name = "rfid")
     var foo: Foo,
     @OneToOne
     @JoinColumns([ "a", "compound", "key"])
     var bar: Bar
) {
   var baz: String
}

and I don't want Foo and Bar to know about FooBarBaz, OneToOne seems to want a bidirectional relationship, and it wasn't happy with me adding multiple JoinColumns. How should I write my JPA entities?

Upvotes: 0

Views: 44

Answers (0)

Related Questions