I'm sure this is a duplicate question, but I can't make it work. I have a one-to-zero-or-one relationship with shared primary key between an entity Home
and an entity Address
.
My problem is that I keep getting an error
Missing column: id
I'm mapping my entities as shown here, but a difference, the column name for my Address
entity is not called id
but homeId_pf
.
Here are my entities:
@Entity
@Table(name = "homes")
@Getter
@Setter
public class Home implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false, updatable = false)
private Long id;
@OneToMany(fetch = EAGER, cascade = {ALL}, orphanRemoval = true)
@JoinColumn(name = "homeId_fk", referencedColumnName = "id", nullable = false)
private Set<Room> rooms = new HashSet<>();
@OneToOne(fetch = EAGER, cascade = {ALL})
@PrimaryKeyJoinColumn
private Address address;
}
@Entity
@Table(name = "addresses")
@Getter
@Setter
public class Address implements Serializable {
@Id
@Column(name = "homeId_pf")
private Long id;
private Integer city;
@MapsId
@OneToOne
@JoinColumn(name = "id")
private Home home;
}
As said, my addresses
table has two columns: homeId_pf
, that is set as PK and a FK to homes.id
and city
.
I've also tried setting @JoinColumn(name = "homeId_pf")
on the Address
class, and @PrimaryKeyJoinColumn(referencedColumnName = "homeId_pf")
on the Home
entity, but it doesn't help.