Closed
Description
When assembling an object with one-to-one relationships, a second level cache miss occurs while trying to assemble the related object. The OneToOneType has the following code:
public override object Assemble(object cached, ISessionImplementor session, object owner)
{
//this should be a call to resolve(), not resolveIdentifier(),
//'cos it might be a property-ref, and we did not cache the
//referenced value
return ResolveIdentifier(session.GetContextEntityIdentifier(owner), session, owner);
}
I'm not sure why the implementation of this function is ignoring the value of cached
, but feel this should be changed to:
public override object Assemble(object cached, ISessionImplementor session, object owner)
{
return ResolveIdentifier(cached, session, owner);
}
or:
public override object Assemble(object cached, ISessionImplementor session, object owner)
{
if (cached != null) {
return ResolveIdentifier(session.GetContextEntityIdentifier(owner), session, owner);
}
return null;
}
Currently when cached
is null, the code presumes that the Id of the one-to-one object is the same as the ID of the owning object. This causes a cache miss and a subsequent query to verify that no related object exists. I'm not sure why the original code does not simply use the cached
Id here..
Hibernate ORM has this same issue, so coordinating a fix in both would benefit all.