Hi all,

assuming we have a Customers and Suppliers with
CustomerCategory/SupplierCategory.
Abstract Category uses table per class hierarchy for
CustomerCategory/SupplierCategory.

Mappings (simplified, just to focus on Customer*):

Customer.hbm.xml:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestCases"
namespace="TestCases.TPH">
    <class name="Customer" table="Customer">
        <id name="Id" column="Id">
            <generator class="native" />
        </id>
        <property name="Name" not-null="true" />
    <many-to-one name="Category" lazy="false" class="CustomerCategory"
column="Category_Id" />
    </class>
</hibernate-mapping>

Category.hbm.xml:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestCases"
namespace="TestCases.TPH">
    <class name="Category" table="Category" mutable="true" abstract="true">
        <id name="Id" column="Id">
            <generator class="native" />
        </id>
        <discriminator column="Type" length="1" />
    <property name="Name" not-null="true" />
    <subclass name="CustomerCategory" discriminator-value="C">
    </subclass>
  </class>
</hibernate-mapping>

In database, column Customer.Category_Id is NULL (Category is not required
for Customer)

Now, let's say we want to query for all customer.Name and
customer.Category.Name (even Customer has no category).
var result = sess.CreateQuery("select c.Name, cat.Name from Customer c left
outer join c.Category cat").List();

NHibernate generates:
select customer0_.Name as x0_0_, customerca1_.Name as x1_0_ from
dbo.Customer customer0_ left outer join dbo.Category customerca1_ on
customer0_.Category_Id=customerca1_.Id where customerca1_.Type='C'

Which is WRONG. It should generate:
select customer0_.Name as x0_0_, customerca1_.Name as x1_0_ from
dbo.Customer customer0_ left outer join dbo.Category customerca1_ on
customer0_.Category_Id=customerca1_.Id AND customerca1_.Type='C'

Notice that discriminator condition should be applied to JOIN clause, not
'WHERE'.
The result is that customers that have no Category are not listed in result
even LEFT OUTER JOIN is used, because NHibernate applies 'Where Type='C'"
condition to whole query which will always filter customers with
Category_Id=NULL.

NHibernate 2.0, SQL Server 2005. I think that was working in NHib 1.2.

Is this a bug or wrong use of table per class hierarchy, or not supported ?

Thanks !
Jozef

--~--~---------~--~----~------------~-------~--~----~
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