开发者

What is the significance of specifying a relationship as 'One to One' in JPA?

开发者 https://www.devze.com 2023-03-30 00:24 出处:网络
i created a class @Entity public class **Department** implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消