-
Notifications
You must be signed in to change notification settings - Fork 933
Improve one-to-one handling in queries #2084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Does it actually make sense to return |
What about criteria? Do the same queries work there? |
Yeah otherwise owner entity thinks that one-to-one entity requires N columns in owner table. And it breaks some other checks in multiple places. |
This comment has been minimized.
This comment has been minimized.
Can we instead find places where it expects |
This comment has been minimized.
This comment has been minimized.
@@ -44,7 +44,8 @@ public override void NullSafeSet(DbCommand st, object value, int index, bool[] s | |||
|
|||
public override void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) | |||
{ | |||
//nothing to do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to make same change to the another overload of NullSafeSet
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Other method is about preparing command for owner table. At least from what I've seen in tests.
How will this work with your other PR #2081? |
…rameterColumnSpan Implement one-to-one handling without owner (to make it work in projections)
@@ -92,6 +96,16 @@ public override ForeignKeyDirection ForeignKeyDirection | |||
|
|||
public override object Hydrate(DbDataReader rs, string[] names, ISessionImplementor session, object owner) | |||
{ | |||
if (owner == null && names.Length > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -7,10 +7,10 @@ namespace NHibernate.Type | |||
{ | |||
internal static class TypeExtensions | |||
{ | |||
public static int GetParameterColumnSpan(this IType type, IMapping sessionFactory) | |||
public static int GetOwnerColumnSpan(this IType type, IMapping sessionFactory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it makes sense to add it to IType
interface.
Done. Introduced
Yes. It works with latest commit. Tests added. |
@@ -324,7 +324,7 @@ public bool IsSimpleValue | |||
|
|||
public virtual bool IsValid(IMapping mapping) | |||
{ | |||
return ColumnSpan == Type.GetColumnSpan(mapping); | |||
return ColumnSpan == Type.GetOwnerColumnSpan(mapping); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break something called "SpecialOneToOneType".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which seems to be unsupported anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. For the code below ColumnSpan
is always 0. So it's never used.
nhibernate-core/src/NHibernate/Mapping/OneToOne.cs
Lines 91 to 103 in c8b9ae6
if (ColumnSpan > 0) | |
{ | |
return | |
new SpecialOneToOneType(ReferencedEntityName, foreignKeyType, referencedPropertyName, IsLazy, UnwrapProxy, | |
entityName, propertyName); | |
} | |
else | |
{ | |
return | |
TypeFactory.OneToOne(ReferencedEntityName, foreignKeyType, referencedPropertyName, IsLazy, UnwrapProxy, | |
entityName, propertyName); | |
} | |
} |
Though I restored original behavior just in case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should override logic for onetone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added GetOwnerColumnSpan
override to SpecialOneToOne
in my latest commit. Or did you mean something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to implement override for IsValid
in OneToOne
to handle this logic. But it's ok.
Added proper column span calculation (mapping related checks extracted to
GetOwnerColumnSpan
);Adjusted
OneToOneType
to be properly handled as parameter and projection in queries;