Now I saw something like this, which seems to go in the same direction:
Code:
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id
@OneToOne
@PrimaryKeyJoinColumn
private Child child;
}
public class Child {
@Id
@GeneratedValue(generator="foreignKeyGenerator")
@org.hibernate.annotations.GenericGenerator(name="foreignKeyGenerator", strategy="foreign",parameters=@Parameter(name="property", value="parent"))
@OneToOne(optional=false)
@JoinColumn(name="id")
private Parent parent;
}
The question is now: does this also work for a uni-directional relationship or do I have to have a bi-directional relationship for this to work?
Thomas