Closed
Description
Incorrect sql generates if
- joined-subclass strategy
- Id columns is not the same
- Using in filters id column
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="NHibernate.Test.JoinedSubclassWithFilter.Person, NHibernate.Test" table="person" proxy="NHibernate.Test.JoinedSubclassWithFilter.Person, NHibernate.Test">
<id name="Id" type="Int32" unsaved-value="0" column="person_id" access="nosetter.camelcase-underscore">
<generator class="native"/>
</id>
<joined-subclass name="NHibernate.Test.JoinedSubclassWithFilter.Employee, NHibernate.Test" table="empl" proxy="NHibernate.Test.JoinedSubclassWithFilter.Employee, NHibernate.Test">
<key column="emp_id"/>
<filter name="filterName" condition="(emp_id in (2, 3))" />
</joined-subclass>
</class>
<filter-def name="filterName" condition="(emp_id in (2, 3))">
</filter-def>
</hibernate-mapping>
one id column is person_id, another is emp_id
filter is emp_id in (2, 3)
namespace NHibernate.Test.JoinedSubclassWithFilter
{
public class Person
{
private int _id = 0;
public virtual int Id
{
get { return _id; }
}
}
public class Employee : Person { }
}
using System.Linq;
using NUnit.Framework;
namespace NHibernate.Test.JoinedSubclassWithFilter
{
[TestFixture]
public class JoinedSubclassWithFilterFixture : TestCase
{
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}
protected override string[] Mappings
{
get { return new string[] { "JoinedSubclassWithFilter.JoinedSubclass.hbm.xml" }; }
}
[Test]
public void TestJoinedSubclassQueryByFilter()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Employee mark = new Employee();
s.Save(mark);
s.Clear();
var ids = s.Query<Employee>().Select(x => x.Id).ToList();
Assert.AreEqual(1, ids.Count);
s.EnableFilter("filterName");
var ids2 = s.Query<Employee>().Select(x => x.Id).ToList();
Assert.AreEqual(0, ids.Count);
s.Delete(mark);
Assert.AreEqual(0, s.CreateQuery("from Person").List().Count);
t.Commit();
s.Close();
}
}
}
Sql that we have
select
employee0_.emp_id as col_0_0_
from empl employee0_
inner join person employee0_1_ on employee0_.emp_id=employee0_1_.person_id
where (employee0_1_.emp_id in (2, 3))
Expected Sql
select
employee0_.emp_id as col_0_0_
from empl employee0_
inner join person employee0_1_ on employee0_.emp_id=employee0_1_.person_id
where (employee0_.emp_id in (2, 3))
Wrong alias for emp_id column (employee0_1_ instead of employee0_)