Permalink
Browse files

Fix NH-1747

SVN: trunk@5752
  • Loading branch information...
1 parent 5883486 commit 1abd74749569709a921952afe86823fcdb34a1f4 @fabiomaulo fabiomaulo committed Apr 23, 2011
@@ -62,10 +62,10 @@
<key column="sid"/>
<property name="Amount" column="dupe"/>
<bag name="Children" lazy="true" inverse="true" >
- <key column="parent"/>
+ <key column="parentId"/>
<one-to-many class="NHibernate.DomainModel.SubMulti, NHibernate.DomainModel"/>
</bag>
- <many-to-one name="Parent" column="parent" />
+ <many-to-one name="Parent" column="parentId" />
<list name="MoreChildren" lazy="true">
<key column="another_parent"/>
<index column="list_ind"/>
@@ -43,7 +43,7 @@ protected override void OnTearDown()
}
}
- [Test, Ignore("The fix was commented in the code. Look for NH-1747")]
+ [Test]
public void TraversingBagToJoinChildElementShouldWork()
{
using (ISession session = OpenSession())
@@ -43,11 +43,11 @@ protected override bool IsDuplicateAssociation(string foreignKeyTable, string[]
InitStatementString(elementPersister, alias, batchSize, subquery);
}
- // NH-1747 FIX
- //protected override string GenerateAliasForColumn(string rootAlias, string column)
- //{
- // return elementPersister.GenerateTableAliasForColumn(rootAlias, column);
- //}
+ protected override string GenerateAliasForColumn(string rootAlias, string column)
+ {
+ // NH-1747 FIX (see OneToManyPersister)
+ return elementPersister.GenerateTableAliasForColumn(rootAlias, column);
+ }
private void InitStatementString(IOuterJoinLoadable elementPersister, string alias, int batchSize, SqlString subquery)
{
@@ -321,21 +321,27 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection,
.ToString();
}
- // NH-1747 FIX
- //protected override SelectFragment GenerateSelectFragment(string alias, string columnSuffix)
- //{
- // var ojl = (IOuterJoinLoadable)ElementPersister;
- // var selectFragment = new SelectFragment(Dialect).SetSuffix(columnSuffix);
- // var columnNames = KeyColumnNames;
- // var columnAliases = KeyColumnAliases;
- // for (int i = 0; i < columnNames.Length; i++)
- // {
- // var column = columnNames[i];
- // var tableAlias = ojl.GenerateTableAliasForColumn(alias, column);
- // selectFragment.AddColumn(tableAlias, column, columnAliases[i]);
- // }
- // return selectFragment;
- //}
+ protected override SelectFragment GenerateSelectFragment(string alias, string columnSuffix)
+ {
+ /*
+ NH-1747 FIX
+ Note: the fix for NH-1747 may cause some problem when the same ColumnName is used to represent two different properties in the same hierarchy
+ In all our test it happened only for NHibernate.Test.Legacy.MultiTableTest.MultiTableCollections
+ The mapping Multi.hbm.xml had a column named "parent" to represent the Key of a set for the relation Lower->Top and SubMulti->SubMulti everything in the same hierarchy
+ NH TODO: Have to add an early check of same ColumnName used to represent two relations.
+ */
+ var ojl = (IOuterJoinLoadable)ElementPersister;
+ var selectFragment = new SelectFragment(Dialect).SetSuffix(columnSuffix);
+ var columnNames = KeyColumnNames;
+ var columnAliases = KeyColumnAliases;
+ for (int i = 0; i < columnNames.Length; i++)
+ {
+ var column = columnNames[i];
+ var tableAlias = ojl.GenerateTableAliasForColumn(alias, column);
+ selectFragment.AddColumn(tableAlias, column, columnAliases[i]);
+ }
+ return selectFragment;
+ }
/// <summary>
/// Create the <see cref="OneToManyLoader" />

0 comments on commit 1abd747

Please sign in to comment.