, , "", hibernate.hbm2ddl.auto persistence.xml, Hibernate "--" . , . @JoinColumn @OneToOne (mappedBy) , Hibernate , FK . , , FK . Hibernate FK , FKg6wt3d1u6o13gdc1hj36ad1ot.
. , Contact (, , ..), OneToOne. , OneToOne , Hibernate , , FK . OneToOne , Hibernate NON-owning , . ( , .)
@Entity
public class Contact implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Integer id;
@Column(name="fn")
private String firstName;
@Column(name="ln")
private String lastName;
@OneToOne(optional=false, mappedBy = "person")
private Director director;
@Entity
public class Director implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Integer id;
@Column(name="title")
private String title;
@OneToOne
@JoinColumn
private Contact person;
public Integer getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Contact getPerson() {
return person;
}
public void setPerson(Contact person) {
this.person = person;
}
, FK Director, :
alter table Director
add constraint FKg6wt3d1u6o13gdc1hj36ad1ot
foreign key (person_id)
references Contact (id)
FK Hibernate Director . , Contact (, ) + "_" + "id", person_id. , @OneToOne (mappedBy = "person" ) . , Hibernate FK , Director.