[hibernate-dev] Is the the optional=false @OneToOne lazy retrieval still relevant

Vlad Mihalcea mihalcea.vlad at gmail.com
Sun Jan 10 11:17:48 EST 2016


Hi Martijn,

I've given more thought to this, and even when the optional=true is
supplied and Hibernate knows there cannot be a null FK on the child-side,
the Persistence Context still needs the child identifier.
Once an entity is managed even if it is a Proxy and not an actual entity,
Hibernate needs the entity identifier to later fetch the association lazily.

In this case the only workaround is to use bytecode instrumentation and
make the parent entity a Proxy so that the child entity is only assigned
upon first access.

The optional=true is also only a JPA hint and Hibernate uses it to validate
that the child entity is set upon persisting, so it doesn't really target
this particular use case only.

Vlad

On Sun, Jan 10, 2016 at 5:20 PM, Martijn Dashorst <
martijn.dashorst at gmail.com> wrote:

> You just ran into a long standing bug with Hibernate, reported over 5
> years ago:
>
> https://hibernate.atlassian.net/browse/HHH-3930
>
> Martijn
>
>
> On Fri, Jan 8, 2016 at 4:08 PM, Vlad Mihalcea <mihalcea.vlad at gmail.com>
> wrote:
> > Hi,
> >
> > I remember that for a bidirectional @OneToOne relationship, the optional
> =
> > false attribute could instruct Hibernate to always generate a Proxy
> > (because this association cannot be null),
> > so, if the fetch is LAZY, it would not generate a secondary query upon
> > fetching the parent-side entity.
> >
> > I tested it with the latest Hibernate, and when fetching the parent
> entity
> > it always generates the secondary select for the child entity too.
> >
> > Is this optimization not relevant anymore or is it an issue?
> >
> > Vlad
> > _______________________________________________
> > hibernate-dev mailing list
> > hibernate-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>


More information about the hibernate-dev mailing list