[hibernate-dev] Does <one-to-one ... constrained="false"> make sense for unidirectional association?

Gail Badner gbadner at redhat.com
Tue Oct 30 01:08:09 EDT 2018


If <one-to-one ... constrained="false"/> does make sense for a
unidirectional association, and the foreign key really should be
FROM_PARENT, then, AFAICT, the only way the unit tests could pass is if
Hibernate assumes such associations would have an implicit
ignoreNotFound="true".

As an example, take a look at OptionalOneToOneTest [1] with the mapping
[2]. The reason why OptionalOneToOneTest passes is because, currently,
OneToOneType#isNullable()
returns foreignKeyType==ForeignKeyDirection.TO_PARENT. For this
association, OneToOneType#isNullable returns true because its foreign key
direction is (incorrectly?) ForeignKeyDirection.TO_PARENT.

[1]
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/onetoone/optional/OptionalOneToOneTest.java
[2]
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/onetoone/optional/Person.hbm.xml


On Mon, Oct 29, 2018 at 9:24 PM Gail Badner <gbadner at redhat.com> wrote:

> The fix for HHH-12436 involves correcting the foreign key direction for
> some one-to-one assocations. In the process of making changes I see that we
> have a unit test that has a unidirectional one-to-one association mapped
> with constrained="false". [1]
>
> ModelBinder assumes that <one-to-one ... constrained = "true"> means that
> the foreign key direction is FROM_PARENT; if constrained = "false", it
> assumes that the foreign key direction is TO_PARENT. [2]
>
> It seems odd to me that the foreign key direction for a unidirectional
> association would be TO_PARENT.
>
> Should the unit test have constrained = "true"?
>
> If not, should ModelBinder check to see if the association is
> bidirectional and determine which side owns the association? This would
> probably require adding a SecondPass.
>
> Please let me know your thoughts.
>
> Regards,
> Gail
>
> [1]
> https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/onetoone/optional/Person.hbm.xml
> [2]
> https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L2114-L2131
>
>


More information about the hibernate-dev mailing list