Index: src/NHibernate.Test/Join/CompositeKey.hbm.xml
===================================================================
--- src/NHibernate.Test/Join/CompositeKey.hbm.xml (revision 0)
+++ src/NHibernate.Test/Join/CompositeKey.hbm.xml (revision 0)
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: src/NHibernate.Test/Join/EmployeeWithCompositeKey.cs
===================================================================
--- src/NHibernate.Test/Join/EmployeeWithCompositeKey.cs (revision 0)
+++ src/NHibernate.Test/Join/EmployeeWithCompositeKey.cs (revision 0)
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NHibernate.Test.Join
+{
+ public class EmployeeWithCompositeKey
+ {
+ private EmployeeWithCompositeKey() { }
+
+ public EmployeeWithCompositeKey(int companyId, int empNumber)
+ {
+ this.Pk = new EmployeePk(companyId, empNumber);
+ }
+
+ private EmployeePk _Pk;
+ public virtual EmployeePk Pk
+ {
+ get { return _Pk; }
+ set { _Pk = value; }
+ }
+
+ private DateTime? _StartDate;
+ public virtual DateTime? StartDate
+ {
+ get { return _StartDate; }
+ set { _StartDate = value; }
+ }
+
+ private string _FirstName;
+ public virtual string FirstName
+ {
+ get { return _FirstName; }
+ set { _FirstName = value; }
+ }
+
+ private string _Surname;
+ public virtual string Surname
+ {
+ get { return _Surname; }
+ set { _Surname = value; }
+ }
+
+ private string _OtherNames;
+ public virtual string OtherNames
+ {
+ get { return _OtherNames; }
+ set { _OtherNames = value; }
+ }
+
+ private string _Title;
+ public virtual string Title
+ {
+ get { return _Title; }
+ set { _Title = value; }
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (this.Pk == null) return false;
+ EmployeeWithCompositeKey other = obj as EmployeeWithCompositeKey;
+
+ if (other == null) return false;
+ if (other.Pk == null) return false;
+
+ return this.Pk.Equals(other.Pk);
+ }
+
+ public override int GetHashCode()
+ {
+ return this.Pk == null ? 0 : this.Pk.GetHashCode();
+ }
+ }
+
+ public class EmployeePk
+ {
+ public EmployeePk() { }
+
+ public EmployeePk(int companyId, int empNumber)
+ {
+ this._CompanyId = companyId;
+ this._EmpNumber = empNumber;
+ }
+
+ private int _CompanyId;
+ public virtual int CompanyId
+ {
+ get { return _CompanyId; }
+ set { _CompanyId = value; }
+ }
+
+ private int _EmpNumber;
+ public virtual int EmpNumber
+ {
+ get { return _EmpNumber; }
+ set { _EmpNumber = value; }
+ }
+
+ public override bool Equals(object obj)
+ {
+ EmployeePk other = obj as EmployeePk;
+ if (other == null)
+ return false;
+ else
+ return (this.CompanyId == other.CompanyId && string.Equals(this.EmpNumber, other.EmpNumber));
+ }
+
+ public override int GetHashCode()
+ {
+ return this.CompanyId.GetHashCode();
+ }
+ }
+}
Index: src/NHibernate.Test/Join/JoinCompositeKeyTest.cs
===================================================================
--- src/NHibernate.Test/Join/JoinCompositeKeyTest.cs (revision 0)
+++ src/NHibernate.Test/Join/JoinCompositeKeyTest.cs (revision 0)
@@ -0,0 +1,92 @@
+using log4net;
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Data;
+
+namespace NHibernate.Test.Join
+{
+ [TestFixture]
+ public class JoinCompositeKeyTest : TestCase
+ {
+ private static ILog log = LogManager.GetLogger(typeof(JoinCompositeKeyTest));
+
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override IList Mappings
+ {
+ get
+ {
+ return new string[] {
+ "Join.CompositeKey.hbm.xml"
+ };
+ }
+ }
+
+ ISession s;
+ ITransaction t;
+
+ protected override void OnSetUp()
+ {
+ s = OpenSession();
+ //t = s.BeginTransaction();
+
+ objectsNeedDeleting.Clear();
+ }
+
+ protected override void OnTearDown()
+ {
+ s.Flush();
+ s.Clear();
+ try
+ {
+ // Delete the objects in reverse order because it is
+ // less likely to violate foreign key constraints.
+ for (int i = objectsNeedDeleting.Count - 1; i >= 0; i--)
+ {
+ s.Delete(objectsNeedDeleting[i]);
+ }
+ s.Flush();
+ }
+ finally
+ {
+ //t.Commit();
+ s.Close();
+ }
+
+ t = null;
+ s = null;
+ }
+
+ private IList objectsNeedDeleting = new ArrayList();
+
+ [Test]
+ public void SimpleSaveAndRetrieve()
+ {
+ EmployeeWithCompositeKey emp = new EmployeeWithCompositeKey(1, 100);
+ emp.StartDate = DateTime.Today;
+ emp.FirstName = "Karl";
+ emp.Surname = "Chu";
+ emp.OtherNames = "The Yellow Dart";
+ emp.Title = "Rock Star";
+ objectsNeedDeleting.Add(emp);
+
+ s.Save(emp);
+ s.Flush();
+ s.Clear();
+
+ EmployeePk pk = new EmployeePk(1, 100);
+ EmployeeWithCompositeKey retrieved = s.Get(pk);
+
+ Assert.IsNotNull(retrieved);
+ Assert.AreEqual(emp.StartDate, retrieved.StartDate);
+ Assert.AreEqual(emp.FirstName, retrieved.FirstName);
+ Assert.AreEqual(emp.Surname, retrieved.Surname);
+ Assert.AreEqual(emp.OtherNames, retrieved.OtherNames);
+ Assert.AreEqual(emp.Title, retrieved.Title);
+ }
+ }
+}
Index: src/NHibernate.Test/NHibernate.Test-2.0.csproj
===================================================================
--- src/NHibernate.Test/NHibernate.Test-2.0.csproj (revision 2826)
+++ src/NHibernate.Test/NHibernate.Test-2.0.csproj (working copy)
@@ -194,6 +194,8 @@
+
+
@@ -930,6 +932,9 @@
+
+
+
@@ -947,4 +952,4 @@
copy "$(ProjectDir)\hibernate.cfg.xml" "hibernate.cfg.xml"
copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"
-
+
\ No newline at end of file
Index: src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs
===================================================================
--- src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs (revision 2826)
+++ src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs (working copy)
@@ -413,7 +413,7 @@
{
keyCols[k++] = col.GetQuotedName(factory.Dialect);
}
- joinKeyColumns.AddRange(keyCols);
+ joinKeyColumns.Add(keyCols);
}
subclassTableSequentialSelect = ArrayHelper.ToBooleanArray(isDeferreds);