-
Notifications
You must be signed in to change notification settings - Fork 932
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
Inserting multiple associations of the same entity fails #3489
Merged
fredericDelaporte
merged 5 commits into
nhibernate:5.4.x
from
mihaicodrean:InsertFromSelectWithMultipleAssociations
Mar 23, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11984a0
Add a failing test for insert from select with multiple associations
mihaicodrean 9265093
Fix bulk insert from children of same parent
fredericDelaporte c12312f
Improve the fix
fredericDelaporte daed952
Generate async files
github-actions[bot] de0787e
Revert an unrelated optimization
fredericDelaporte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace NHibernate.Test.BulkManipulation | ||
{ | ||
public class Course | ||
{ | ||
public virtual long CourseId { get; set; } | ||
public virtual string Description { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.BulkManipulation | ||
{ | ||
[Serializable] | ||
public class Enrolment | ||
{ | ||
public virtual long EnrolmentId { get; set; } | ||
public virtual Student Student { get; set; } | ||
public virtual Course Course { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0"?> | ||
<hibernate-mapping | ||
xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.BulkManipulation"> | ||
|
||
<class name="Course"> | ||
<id name="CourseId"> | ||
<generator class="native" /> | ||
</id> | ||
<property name="Description" /> | ||
</class> | ||
|
||
<class name="Student"> | ||
<id name="StudentId"> | ||
<generator class="native" /> | ||
</id> | ||
<property name="Name" /> | ||
</class> | ||
|
||
<class name="Enrolment"> | ||
<id name="EnrolmentId"> | ||
<generator class="native" /> | ||
</id> | ||
<many-to-one name="Student" column="StudentId" class="Student" /> | ||
<many-to-one name="Course" column="CourseId" class="Course" /> | ||
</class> | ||
|
||
</hibernate-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace NHibernate.Test.BulkManipulation | ||
{ | ||
public class Student | ||
{ | ||
public virtual long StudentId { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
processedElements
set serves a de-duplication purpose of selected entities. But, alone, it fails accounting for associations selected in shallow queries which will be seen as having the same fromElement although being actually different entities being selected.Shallow queries may still have duplicated entities selected and cannot be entirely ignored for the de-duplication, if we want to keep the test
HqlDuplicateEntitySelectionSubQuery
as currently is. (I fail to understand why this tests is valid, why should we support the queries in this test, but I did not get answers about this here. And anyway, it has been release in 5.4, so, it is legacy.)The
DOT
check allows to recognize cases in shallow queries where the same fromElement may be used by different expressions selecting different things, and a such, needing to be not falsely de-duplicated.(I thought about checking if the expressions
e
where "the same" (having same Path) instead when sharing a common fromElement, but that would imply building a dictionary of sets instead ofprocessedElements
. I do not consider it is worth it.)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.
To be honest, I don't remember why I've added such test. Looking back at it, I agree that the test shouldn't be added.
Perhaps we could add a TODO for removing test
HqlDuplicateEntitySelectionSubQuery
in version5.5
and remove thenode.Type == SqlGenerator.DOT
part from the condition.