What is the significance of specifying a relationship as 'One to One' in JPA?
i created a class
@Entity
public class **Department** implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToOne
private **Doctor** head;
.........
}
As per the spec, when an entity Department references a single entity Doctor, no other Department s can refer the same Doctor 开发者_Go百科But i could make 2 different Department s refer to the same Doctor
ie, the Doctor id in the department table is not Unique
how its possible?
The mapping only describes how your entities should be saved to/loaded from the database. It doesn't automatically insert constraints in the database schema, and does not make sure that all the data you create respects the mapping.
You must create and enable the appropriate constraints in the database schema.
精彩评论