Hello,

using nhibernate trunk I found behaviour which I think is a bug, but
posting here
here before putting it to JIRA to confirm it's really a bug.

Testcase behavior:
Can_Query_Without_Collection_Size_Condition always pass
Can_Query_With_Collection_Size_Condition fails and exception is
thrown:

14:38:53,181 WARN  ADOExceptionReporter:32 -
System.Data.SqlClient.SqlException: The parameterized query '(@p0
bit,@p1 int,@p2 bit)select customer0_.Id as Id0_0_, orders1' expects
the parameter '@p2', which was not supplied.

NHibernate produces @p2 = NULL, it should be @p =
VALUE_OF_SESSION_FILTER

Note: Commenting out sess.EnableFilter("state").SetParameter
("deleted", false);
gets both tests to pass (even filters are not used in queries
obviously)


Testcase:

Domain:
 public class Customer
    {
        public virtual int Id { get; set; }
        public virtual bool IsDeleted { get; set; }
        public virtual IList<Order> Orders { get; set; }
    }

    public class Order
    {
        public virtual int Id { get; set; }
        public virtual bool IsDeleted { get; set; }
        public virtual string Memo { get; set; }
        public virtual Customer Customer { get; set; }
    }

Mappings:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        
namespace="NHibernate.Test.NHSpecificTest.CollectionFilterQuery"
                                   assembly="NHibernate.Test">

  <class name="Customer" table="Customers">
    <id name="Id">
      <generator class="native" />
    </id>
    <bag name="Orders">
      <key column="Customer_Id" />
      <one-to-many class="Order" />
      <filter name="state" condition=":deleted = IsDeleted" />
    </bag>
    <property name="IsDeleted" not-null="true" />
  </class>

  <class name="Order" table="Orders">
    <id name="Id">
      <generator class="native" />
    </id>
    <property name="IsDeleted" not-null="true" />
    <property name="Memo" not-null="false" />
    <many-to-one name="Customer" class="Customer"
column="Customer_Id" />
    <filter name="state" condition=":deleted = IsDeleted" />
  </class>

  <filter-def name="state" condition=":deleted = IsDeleted">
    <filter-param name="deleted" type="Boolean"/>
  </filter-def>
</hibernate-mapping>


Fixture:
[TestFixture]
    public class Fixture : BugTestCase
    {
        [Test]
        public void Can_Query_Without_Collection_Size_Condition()
        {
            using (ISession sess = OpenSession())
            using (ITransaction tx = sess.BeginTransaction())
            {
                sess.SaveOrUpdate(new Customer() { IsDeleted =
false });
                tx.Commit();
            }

            using (ISession sess = OpenSession())
            using (ITransaction tx = sess.BeginTransaction())
            {
                sess.EnableFilter("state").SetParameter("deleted",
false);

                var result = sess
                    .CreateQuery("from Customer c join c.Orders o
where c.id > :cid")
                    .SetParameter("cid", 0)
                    .List();
                Assert.That(result.Count == 0);
                tx.Commit();
            }

            using (ISession sess = OpenSession())
            using (ITransaction tx = sess.BeginTransaction())
            {
                sess.Delete("from System.Object");
                tx.Commit();
            }
        }

        [Test]
        public void Can_Query_With_Collection_Size_Condition()
        {
            using (ISession sess = OpenSession())
            using (ITransaction tx = sess.BeginTransaction())
            {
                sess.SaveOrUpdate(new Customer() { IsDeleted =
false });
                tx.Commit();
            }

            using (ISession sess = OpenSession())
            using (ITransaction tx = sess.BeginTransaction())
            {
                sess.EnableFilter("state").SetParameter("deleted",
false);

                var result = sess
                    .CreateQuery("from Customer c join c.Orders o
where c.id > :cid and c.Orders.size > 0")
                    .SetParameter("cid", 0)
                    .List();
                Assert.That(result.Count == 0);
                tx.Commit();
            }

            using (ISession sess = OpenSession())
            using (ITransaction tx = sess.BeginTransaction())
            {
                sess.Delete("from System.Object");
                tx.Commit();
            }
        }
    }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to