[hibernate-dev] Mapping defaults for @OneToOne
Gail Badner
gbadner at redhat.com
Wed Dec 3 00:34:24 EST 2014
I'm a bit confused by the mapping defaults for @OneToOne defined in JPA 2.1.
Sections 2.10.1 and 2.10.3.1 (Bidirectional and Unidirectional OneToOne Relationships) says, "The foreign key column has the same type as the primary key of table B and there is a unique key constraint on it."
Section 11.1.41 (OneToOne Annotation) says that, by default, optional=true, which translates into nullable foreign key column(s).
IIUC, the default mapping is not supported by many (all?) databases, because a constraint violation exception will be thrown if a column has a unique key constraint and there is more than one null value for that column.
Currently, Hibernate does not create a unique key unless @OneToOne( optional=false ) is defined. I believe Hibernate is doing the right thing here, but it is not consistent with the spec.
Is the spec wrong in this case, or am I missing something? Please let me know...
Thanks,
Gail
More information about the hibernate-dev
mailing list