Skip to content

Commit 6669e4e

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
Fix caching of OneToOneType from second level cache.
1 parent 4658956 commit 6669e4e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/NHibernate/Type/OneToOneType.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,32 @@ public override bool UseLHSPrimaryKey
135135

136136
public override object Disassemble(object value, ISessionImplementor session, object owner)
137137
{
138-
return null;
138+
if (value == null)
139+
{
140+
return null;
141+
}
142+
143+
object id = ForeignKeys.GetEntityIdentifierIfNotUnsaved(GetAssociatedEntityName(), value, session);
144+
145+
if (id == null)
146+
{
147+
throw new AssertionFailure("cannot cache a reference to an object with a null id: " + GetAssociatedEntityName());
148+
}
149+
150+
return GetIdentifierType(session).Disassemble(id, session, owner);
139151
}
140152

141153
public override object Assemble(object cached, ISessionImplementor session, object owner)
142154
{
143-
//this should be a call to resolve(), not resolveIdentifier(),
144-
//'cos it might be a property-ref, and we did not cache the
145-
//referenced value
146-
return ResolveIdentifier(session.GetContextEntityIdentifier(owner), session, owner);
155+
// the owner of the association is not the owner of the id
156+
object id = GetIdentifierType(session).Assemble(cached, session, null);
157+
158+
if (id == null)
159+
{
160+
return null;
161+
}
162+
163+
return ResolveIdentifier(id, session);
147164
}
148165

149166
/// <summary>

0 commit comments

Comments
 (0)