From: <fab...@us...> - 2011-03-27 19:31:29
|
Revision: 5554 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5554&view=rev Author: fabiomaulo Date: 2011-03-27 19:31:22 +0000 (Sun, 27 Mar 2011) Log Message: ----------- Partial fix of NH-1747 and commented the full fix Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -712,6 +712,18 @@ throw new MappingException("Association references unmapped class: " + associatedEntityName); oneToMany.AssociatedClass = persistentClass; model.CollectionTable = persistentClass.Table; + if (model.IsInverse && persistentClass.JoinClosureSpan > 0) + { + // NH: bidirectional one-to-many with a class splitted in more tables; have to find in which table is the inverse side + foreach (var joined in persistentClass.JoinClosureIterator) + { + if (collectionMapping.Key.Columns.Select(x=> x.name).All(x => joined.Table.ColumnIterator.Select(jc=> jc.Name).Contains(x))) + { + model.CollectionTable = joined.Table; + break; + } + } + } if (log.IsInfoEnabled) log.Info("mapping collection: " + model.Role + " -> " + model.CollectionTable.Name); Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/OneToManyJoinWalker.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -13,6 +13,7 @@ /// <seealso cref="OneToManyLoader" /> public class OneToManyJoinWalker : CollectionJoinWalker { + private readonly IOuterJoinLoadable elementPersister; private readonly IQueryableCollection oneToManyPersister; protected override bool IsDuplicateAssociation(string foreignKeyTable, string[] foreignKeyColumns) @@ -28,7 +29,7 @@ : base(factory, enabledFilters) { this.oneToManyPersister = oneToManyPersister; - IOuterJoinLoadable elementPersister = (IOuterJoinLoadable) oneToManyPersister.ElementPersister; + elementPersister = (IOuterJoinLoadable)oneToManyPersister.ElementPersister; string alias = GenerateRootAlias(oneToManyPersister.Role); WalkEntityTree(elementPersister, alias); @@ -42,6 +43,12 @@ InitStatementString(elementPersister, alias, batchSize, subquery); } + // NH-1747 FIX + //protected override string GenerateAliasForColumn(string rootAlias, string column) + //{ + // return elementPersister.GenerateTableAliasForColumn(rootAlias, column); + //} + private void InitStatementString(IOuterJoinLoadable elementPersister, string alias, int batchSize, SqlString subquery) { int joins = CountEntityPersisters(associations); Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -1752,6 +1752,11 @@ get { return keyColumnNames; } } + protected string[] KeyColumnAliases + { + get { return keyColumnAliases; } + } + public bool IsLazy { get { return isLazy; } Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/OneToManyPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -321,6 +321,22 @@ .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; + //} + /// <summary> /// Create the <see cref="OneToManyLoader" /> /// </summary> Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -1817,7 +1817,7 @@ } } - public string GenerateTableAliasForColumn(string rootAlias, string column) + public virtual string GenerateTableAliasForColumn(string rootAlias, string column) { int propertyIndex = Array.IndexOf(SubclassColumnClosure, column); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs 2011-03-27 17:34:26 UTC (rev 5553) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1747/Fixture.cs 2011-03-27 19:31:22 UTC (rev 5554) @@ -2,7 +2,7 @@ namespace NHibernate.Test.NHSpecificTest.NH1747 { - [TestFixture,Ignore] + [TestFixture] public class JoinTraversalTest : BugTestCase { [Test] @@ -43,14 +43,13 @@ } } - [Test] + [Test, Ignore("The fix was commented in the code. Look for NH-1747")] public void TraversingBagToJoinChildElementShouldWork() { using (ISession session = OpenSession()) { var paymentBatch = session.Get<PaymentBatch>(3); Assert.AreEqual(1, paymentBatch.Payments.Count); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |