So typically a OneToOne has it's own PK and a FK back to the related object. So typically it is the same as a OneToMany in terms of PK and FK but with an additional unique constraint to restrict the cardinality. This is different from this case.
So for this example Stock does not have a @Id specified. Assuming that Stock is effectively read only then I think you should define it's @Id to be 'good' and it's FK would also be 'good' - so it's PK and FK are mapped to the same column.
That should work.
Alternatively you could use @Formula properties on Good.
Cheers, Rob.
So typically a OneToOne has it's own PK and a FK back to the related object. So typically it is the same as a OneToMany in terms of PK and FK but with an additional unique constraint to restrict the cardinality.
This is different from this case.
So for this example Stock does not have a @Id specified. Assuming that Stock is effectively read only then I think you should define it's @Id to be 'good' and it's FK would also be 'good' - so it's PK and FK are mapped to the same column.
That should work.
You should use @OneToOne on both sides. Sorry, the bit earlier about OneToMany probably was more confusing than helpful.
I think it should be something like:
public class Good
...
@OneToOne(mappedBy="good")
private StockLine stockState;
public class StockLine
...
@Id
@Column(name="good")
private Long id;
@OneToOne
@JoinColumn(name="good", nullable = false)private Good good;