I have these two classes:
Code:
@Entity
public class Parent implements Serializable {
@Id
@GeneratedValue
private long id;
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
private Child child;
}
and
Code:
@Entity
public class Child implements Serializable {
@Id
@GeneratedValue
long id;
@OneToOne(cascade = CascadeType.ALL, optional = true)
private Parent parent;
}
The mapping column "parent_id" in the Child table is not unique. How can I make it unqiue?
If I specify @UniqueConstraint there are 2 indexes in the DB (MySQL) - one from OneToOne relation and one from the constraint. If I go for the foreign key approach with @JoinColumn(unique=true) the MySQL again contains index and unique index.