Skip to content
Browse files

Fixed NH-1064. This problem does exist on the current trunk.

SVN: branches/1.2.x@3039
  • Loading branch information...
1 parent 575ccc4 commit 961eaf255c2947a724c888334ec6c0f5e0fd62ee Karl Chu committed Oct 8, 2007
View
67 src/NHibernate.Test/NHSpecificTest/NH1064/Fixture.cs
@@ -0,0 +1,67 @@
+using NUnit.Framework;
+
+using System;
+using System.Collections;
+using System.Text;
+
+namespace NHibernate.Test.NHSpecificTest.NH1064
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ public override string BugNumber
+ {
+ get { return "NH1064"; }
+ }
+
+ protected override void OnTearDown()
+ {
+ base.OnTearDown();
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Delete("from TypeC");
+ s.Delete("from TypeB");
+ s.Delete("from TypeA");
+
+ tx.Commit();
+ }
+ }
+
+ [Test]
+ public void JoinFetch()
+ {
+ TypeA a1;
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ a1 = new TypeA("a1");
+ a1.C = new TypeC("c1", "c1");
+ s.Save(a1.C);
+ s.Save(a1);
+
+ tx.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ ICriteria crit = s.CreateCriteria(typeof(TypeA))
+ .SetFetchMode("Bs", FetchMode.Join)
+ .SetFetchMode("C", FetchMode.Join);
+ // According to the issue description, the following line
+ // would have thown an NHibernate.ADOException before the fix
+ IList result = crit.List();
+
+ Assert.AreEqual(1, result.Count);
+ Assert.AreEqual(a1.Id, (result[0] as TypeA).Id);
+ Assert.AreEqual(a1.Name, (result[0] as TypeA).Name);
+ Assert.AreEqual(a1.C.Id, (result[0] as TypeA).C.Id);
+ Assert.AreEqual(a1.C.Name, (result[0] as TypeA).C.Name);
+
+ tx.Commit();
+ }
+ }
+ }
+}
View
33 src/NHibernate.Test/NHSpecificTest/NH1064/Mappings.hbm.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1064"
+ assembly="NHibernate.Test"
+>
+ <class name="TypeA" table="NH1064_A">
+ <id name="Id">
+ <generator class="native"/>
+ </id>
+ <property name="Name"/>
+ <!-- The mapping of "C" must come before the mapping of "Bs" for the bug to manifest itself -->
+ <many-to-one name="C" column="C_Id" lazy="proxy"/>
+ <set name="Bs" lazy="true" cascade="all-delete-orphan">
+ <key column="A_Id"/>
+ <one-to-many class="TypeB"/>
+ </set>
+ </class>
+
+ <class name="TypeB" table="NH1064_B">
+ <id name="Id">
+ <generator class="native"/>
+ </id>
+ <property name="Name"/>
+ </class>
+
+ <class name="TypeC" table="NH1064_C">
+ <!-- PK type of C must be a string (or perhaps something other than an int) for the bug to manifest itself -->
+ <id name="Id" type="string">
+ <generator class="assigned"/>
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
View
93 src/NHibernate.Test/NHSpecificTest/NH1064/Model.cs
@@ -0,0 +1,93 @@
+using Iesi.Collections;
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NHibernate.Test.NHSpecificTest.NH1064
+{
+ public class TypeA
+ {
+ public TypeA() { }
+ public TypeA(string name) { this._Name = name; }
+
+ private int _Id;
+ public virtual int Id
+ {
+ get { return _Id; }
+ set { _Id = value; }
+ }
+
+ private string _Name;
+ public virtual string Name
+ {
+ get { return _Name; }
+ set { _Name = value; }
+ }
+
+ private ISet _Bs = new HashedSet();
+ public virtual ISet Bs
+ {
+ get { return _Bs; }
+ set { _Bs = value; }
+ }
+
+ private TypeC _C;
+ public virtual TypeC C
+ {
+ get { return _C; }
+ set { _C = value; }
+ }
+ }
+
+ public class TypeB
+ {
+ public TypeB() { }
+ public TypeB(string name) { this._Name = name; }
+
+ private int _Id;
+ public virtual int Id
+ {
+ get { return _Id; }
+ set { _Id = value; }
+ }
+
+ private string _Name;
+ public virtual string Name
+ {
+ get { return _Name; }
+ set { _Name = value; }
+ }
+
+ private TypeA _A;
+ public virtual TypeA A
+ {
+ get { return _A; }
+ set { _A = value; }
+ }
+ }
+
+ public class TypeC
+ {
+ public TypeC() { }
+ public TypeC(string id, string name)
+ {
+ this._Id = id;
+ this._Name = name;
+ }
+
+ private string _Id;
+ public virtual string Id
+ {
+ get { return _Id; }
+ set { _Id = value; }
+ }
+
+ private string _Name;
+ public virtual string Name
+ {
+ get { return _Name; }
+ set { _Name = value; }
+ }
+ }
+}
View
7 src/NHibernate.Test/NHibernate.Test-2.0.csproj
@@ -221,6 +221,8 @@
<Compile Include="NHSpecificTest\BasicTimeFixture.cs" />
<Compile Include="NHSpecificTest\BugTestCase.cs" />
<Compile Include="NHSpecificTest\CollectionFixture.cs" />
+ <Compile Include="NHSpecificTest\NH1064\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1064\Model.cs" />
<Compile Include="NHSpecificTest\NH1119\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1119\Model.cs" />
<Compile Include="NHSpecificTest\NH1018\Employee.cs" />
@@ -917,6 +919,9 @@
<EmbeddedResource Include="NHSpecificTest\NH1119\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="NHSpecificTest\NH1064\Mappings.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
@@ -934,4 +939,4 @@
copy "$(ProjectDir)\hibernate.cfg.xml" "hibernate.cfg.xml"
copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent>
</PropertyGroup>
-</Project>
+</Project>
View
26 src/NHibernate/Loader/Loader.cs
@@ -681,21 +681,21 @@ ISessionImplementor session
EntityKey ownerKey = keys[owner];
if (keys[i] == null && ownerKey != null)
{
- //bool isOneToOneAssociation = ownerAssociationTypes != null &&
- // ownerAssociationTypes[ i ] != null &&
- // ownerAssociationTypes[ i ].IsOneToOne;
-
- //if( isOneToOneAssociation )
- //{
- // Added to fix NH-687, not in Hibernate:
- bool isUniqueKeyReference = ownerAssociationTypes != null &&
- ownerAssociationTypes[i] != null &&
- ownerAssociationTypes[i].IsUniqueKeyReference;
- if (!isUniqueKeyReference)
+ bool isOneToOneAssociation = ownerAssociationTypes != null &&
+ ownerAssociationTypes[i] != null &&
+ ownerAssociationTypes[i].IsOneToOne;
+
+ if (isOneToOneAssociation)
{
- session.AddNonExist(new EntityKey(ownerKey.Identifier, persisters[i]));
+ // Added to fix NH-687, not in Hibernate:
+ bool isUniqueKeyReference = ownerAssociationTypes != null &&
+ ownerAssociationTypes[i] != null &&
+ ownerAssociationTypes[i].IsUniqueKeyReference;
+ if (!isUniqueKeyReference)
+ {
+ session.AddNonExist(new EntityKey(ownerKey.Identifier, persisters[i]));
+ }
}
- //}
}
}
}

0 comments on commit 961eaf2

Please sign in to comment.
Something went wrong with that request. Please try again.