|
From: <fab...@us...> - 2009-05-31 22:33:08
|
Revision: 4395
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4395&view=rev
Author: fabiomaulo
Date: 2009-05-31 22:33:06 +0000 (Sun, 31 May 2009)
Log Message:
-----------
Fix NH-1801
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Domain.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs 2009-05-31 20:53:09 UTC (rev 4394)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs 2009-05-31 22:33:06 UTC (rev 4395)
@@ -70,35 +70,45 @@
MutateRowValueConstructorSyntaxesIfNecessary( lhsType, rhsType );
}
- protected void MutateRowValueConstructorSyntaxesIfNecessary(IType lhsType, IType rhsType)
+ protected void MutateRowValueConstructorSyntaxesIfNecessary(IType lhsType, IType rhsType)
{
// TODO : this really needs to be delayed unitl after we definitively know all node types
// where this is currently a problem is parameters for which where we cannot unequivocally
// resolve an expected type
ISessionFactoryImplementor sessionFactory = SessionFactoryHelper.Factory;
- if ( lhsType != null && rhsType != null )
+ if (lhsType != null && rhsType != null)
{
- int lhsColumnSpan = lhsType.GetColumnSpan( sessionFactory );
- if ( lhsColumnSpan != rhsType.GetColumnSpan( sessionFactory ) )
+ int lhsColumnSpan = lhsType.GetColumnSpan(sessionFactory);
+ var rhsColumnSpan = rhsType.GetColumnSpan(sessionFactory);
+ // NH different behavior NH-1801
+ if (lhsColumnSpan != rhsColumnSpan && !AreCompatibleEntityTypes(lhsType, rhsType))
{
- throw new TypeMismatchException(
- "left and right hand sides of a binary logic operator were incompatibile [" +
- lhsType.Name + " : "+ rhsType.Name + "]"
- );
+ throw new TypeMismatchException("left and right hand sides of a binary logic operator were incompatibile ["
+ + lhsType.Name + " : " + rhsType.Name + "]");
}
- if ( lhsColumnSpan > 1 )
+ if (lhsColumnSpan > 1)
{
// for dialects which are known to not support ANSI-SQL row-value-constructor syntax,
// we should mutate the tree.
- if ( !sessionFactory.Dialect.SupportsRowValueConstructorSyntax)
+ if (!sessionFactory.Dialect.SupportsRowValueConstructorSyntax)
{
- MutateRowValueConstructorSyntax( lhsColumnSpan );
+ MutateRowValueConstructorSyntax(lhsColumnSpan);
}
}
}
}
+ private static bool AreCompatibleEntityTypes(IType lhsType, IType rhsType)
+ {
+ if(lhsType.IsEntityType && rhsType.IsEntityType)
+ {
+ return lhsType.ReturnedClass.IsAssignableFrom(rhsType.ReturnedClass) ||
+ rhsType.ReturnedClass.IsAssignableFrom(lhsType.ReturnedClass);
+ }
+ return false;
+ }
+
/**
* Mutate the subtree relating to a row-value-constructor to instead use
* a series of ANDed predicates. This allows multi-column type comparisons
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Domain.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Domain.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Domain.cs 2009-05-31 22:33:06 UTC (rev 4395)
@@ -0,0 +1,24 @@
+namespace NHibernate.Test.NHSpecificTest.NH1801
+{
+ public class A
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+ }
+
+ public class B
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+
+ public virtual A A { get; set; }
+ }
+
+ public class C
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+
+ public virtual A A { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Fixture.cs 2009-05-31 22:33:06 UTC (rev 4395)
@@ -0,0 +1,57 @@
+using System.Collections;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1801
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ [Test]
+ public void Test()
+ {
+ try
+ {
+ using (ISession s = OpenSession())
+ {
+ var a1 = new A {Id = 1, Name = "A1"};
+ var a2 = new A {Id = 2, Name = "A2"};
+
+ var b1 = new B {Id = 1, Name = "B1", A = a1};
+ var b2 = new B {Id = 2, Name = "B2", A = a2};
+
+ var c1 = new C {Name = "C1", A = a1};
+ var c2 = new C {Name = "C2", A = a2};
+
+ s.Save(a1);
+ s.Save(a2);
+ s.Save(b1);
+ s.Save(b2);
+ s.Save(c1);
+ s.Save(c2);
+
+ s.Flush();
+ }
+
+ using (ISession s = OpenSession())
+ {
+ IList res = s.CreateQuery("from B b, C c where b.A = c.A and b.Id = :id").SetInt32("id", 1).List();
+
+ Assert.That(res, Has.Count.EqualTo(1));
+
+ s.Flush();
+ }
+ }
+ finally
+ {
+ using (ISession s = OpenSession())
+ {
+ s.Delete("from B");
+ s.Delete("from C");
+ s.Delete("from A");
+
+ s.Flush();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1801/Mappings.hbm.xml 2009-05-31 22:33:06 UTC (rev 4395)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1801"
+ assembly="NHibernate.Test">
+
+ <class name="A">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+
+ <property name="Name" />
+ </class>
+
+ <class name="B">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+
+ <property name="Name" />
+
+ <many-to-one name="A"/>
+ </class>
+
+ <class name="C">
+ <id name="Id">
+ <generator class="foreign">
+ <param name="property">A</param>
+ </generator>
+ </id>
+ <property name="Name" />
+
+ <one-to-one name="A" class="A" constrained="true"/>
+
+ <!--using a many-to-one assosciation instead makes the test succeed -->
+
+ <!--<many-to-one name="A"></many-to-one>-->
+ </class>
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-31 20:53:09 UTC (rev 4394)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-31 22:33:06 UTC (rev 4395)
@@ -446,6 +446,8 @@
<Compile Include="NHSpecificTest\NH1794\Person.cs" />
<Compile Include="NHSpecificTest\NH1796\Entity.cs" />
<Compile Include="NHSpecificTest\NH1796\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1801\Domain.cs" />
+ <Compile Include="NHSpecificTest\NH1801\Fixture.cs" />
<Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" />
<Compile Include="HQL\HQLFunctions.cs" />
<Compile Include="HQL\Human.cs" />
@@ -1840,6 +1842,7 @@
<EmbeddedResource Include="Ado\AlmostSimple.hbm.xml" />
<EmbeddedResource Include="CacheTest\EntityWithFilters.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1801\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1796\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1553\MsSQL\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1788\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|