|
From: <pa...@us...> - 2011-01-16 22:48:52
|
Revision: 5356
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5356&view=rev
Author: patearl
Date: 2011-01-16 22:48:45 +0000 (Sun, 16 Jan 2011)
Log Message:
-----------
HQL: Fixed a bug relating to composite key SQL generation (NH-2280, Thanks Alex Baker).
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/InvalidSqlTest.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Organisation.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/OrganisationCode.cs
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs 2011-01-16 21:55:41 UTC (rev 5355)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs 2011-01-16 22:48:45 UTC (rev 5356)
@@ -459,7 +459,10 @@
}
string result = StringHelper.Join(", ", cols);
- return cols.Length == 1 ? result : "(" + result + ")";
+ // There used to be code here that added parentheses if the number of columns was greater than one.
+ // This was causing invalid queries like select (c1, c2) from x. I couldn't think of a reason that
+ // parentheses would be wanted around a list of columns, so I removed them.
+ return result;
}
public void HandlePropertyBeingDereferenced(IType propertySource, string propertyName)
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/InvalidSqlTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/InvalidSqlTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/InvalidSqlTest.cs 2011-01-16 22:48:45 UTC (rev 5356)
@@ -0,0 +1,24 @@
+using System;
+
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using NHibernate.Dialect;
+using NHibernate.Linq;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH2280
+{
+ [TestFixture]
+ public class InvalidSqlTest : BugTestCase
+ {
+ [Test]
+ public void CompositeKeyTest()
+ {
+ using (ISession session = OpenSession())
+ {
+ session.Query<Organisation>().Where(o => o.Codes.Any(c => c.Key.Code == "1476")).ToList();
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Mappings.hbm.xml 2011-01-16 22:48:45 UTC (rev 5356)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH2280">
+ <class name="Organisation" abstract="false" table="tblTrnOrganisation">
+ <id name="OrganisationId">
+ <generator class="guid"></generator>
+ </id>
+ <property name="LegalName" column="OrganisationLegalName"/>
+ <property name="Abn" />
+ <property name="Acn" />
+
+ <set name="Codes" table="tblTrnRtoCode" cascade="all-delete-orphan" inverse="true" >
+ <key column="OrganisationId"/>
+ <one-to-many class="OrganisationCode"/>
+ </set>
+ </class>
+
+ <class name="OrganisationCode" table="tblTrnRtoCode" dynamic-insert="true" dynamic-update="true">
+ <composite-id class="NHibernate.Test.NHSpecificTest.NH2280.OrganisationCodeKey, NHibernate.Test" name="Key" >
+ <key-many-to-one column="OrganisationId" class="Organisation" name="Organisation"/>
+ <key-property column="RtoCode" name="Code"/>
+ <key-property column="RtoCodeStartDate" name="StartDate"/>
+ </composite-id>
+ <property name="EndDate" column="RtoCodeEndDate"/>
+ </class>
+</hibernate-mapping>
+
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Organisation.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Organisation.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/Organisation.cs 2011-01-16 22:48:45 UTC (rev 5356)
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Iesi.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH2280
+{
+ public class Organisation
+ {
+ public virtual Guid OrganisationId { get; set; }
+
+ public virtual ISet<OrganisationCode> Codes { get; protected internal set; }
+
+ public virtual string LegalName { get; set; }
+ public virtual string Abn { get; set; }
+ public virtual string Acn { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/OrganisationCode.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/OrganisationCode.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2280/OrganisationCode.cs 2011-01-16 22:48:45 UTC (rev 5356)
@@ -0,0 +1,93 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Text;
+
+namespace NHibernate.Test.NHSpecificTest.NH2280
+{
+ public class OrganisationCode
+ {
+ private OrganisationCodeKey key = new OrganisationCodeKey();
+
+ public virtual DateTime StartDate
+ {
+ get { return key.StartDate; }
+ set { key.StartDate = value; }
+ }
+
+ public virtual string Code
+ {
+ get { return key.Code; }
+ set { key.Code = value; }
+ }
+
+ public virtual OrganisationCodeKey Key
+ {
+ get { return key; }
+ protected set { key = value; }
+ }
+
+ /// <summary>
+ /// Need comments for intellisense.
+ /// </summary>
+ public virtual Organisation Organisation
+ {
+ get { return key.Organisation; }
+ set { key.Organisation = value; }
+ }
+
+
+ public virtual DateTime? EndDate { get; set; }
+
+ public override bool Equals(object obj)
+ {
+ var other = obj as OrganisationCodeKey;
+ if (other == null)
+ {
+ return false;
+ }
+
+ return this.Code == other.Code && this.StartDate == other.StartDate;
+ }
+
+ public override int GetHashCode()
+ {
+ return Code == null ? 0 : Code.GetHashCode() ^ StartDate.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return Code;
+ }
+ }
+
+ /// <summary>
+ /// blah blah blah
+ /// </summary>
+ [Serializable,
+ DebuggerDisplay("Organisation: {Organisation}, Code: {Code}, StartDate: {StartDate:d}")]
+ public class OrganisationCodeKey
+ {
+ public string Code { get; set; }
+ public DateTime StartDate { get; set; }
+ public Organisation Organisation { get; set; }
+
+ public override bool Equals(object obj)
+ {
+ OrganisationCodeKey other = obj as OrganisationCodeKey;
+ if (other == null)
+ {
+ return false;
+ }
+
+ return this.Organisation.OrganisationId == other.Organisation.OrganisationId && this.Code == other.Code &&
+ this.StartDate == other.StartDate;
+ }
+
+ public override int GetHashCode()
+ {
+ return (Organisation == null ? 0 : Organisation.GetHashCode()) ^ (Code == null ? 0 : Code.GetHashCode())
+ ^ StartDate.GetHashCode();
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-01-16 21:55:41 UTC (rev 5355)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-01-16 22:48:45 UTC (rev 5356)
@@ -521,6 +521,9 @@
<Compile Include="NHSpecificTest\NH2279\B.cs" />
<Compile Include="NHSpecificTest\NH2279\C.cs" />
<Compile Include="NHSpecificTest\NH2279\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2280\InvalidSqlTest.cs" />
+ <Compile Include="NHSpecificTest\NH2280\Organisation.cs" />
+ <Compile Include="NHSpecificTest\NH2280\OrganisationCode.cs" />
<Compile Include="NHSpecificTest\NH2287\Domain.cs" />
<Compile Include="NHSpecificTest\NH2287\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2288\Fixture.cs" />
@@ -2375,6 +2378,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="NHSpecificTest\NH2280\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2203\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\BagWithLazyExtraAndFilter\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2470\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|