mappings:
Status is abstract with 1:1 relations to other tables.
Some of the tables have a property ReviewDate, others do not.
in this snippet PrepareStatus and InServiceStatus have the ReviewDate
property. The DisposeStatus does not.
<hibernate-mapping>
        <class name="Status" abstract="true">
                <id name="Id">
                        <generator class="identity" />
                </id>
                ...
        </class>

        <joined-subclass extends="Status" name="PrepareStatus">
                <key column="id" on-delete="cascade" />
                <property name="ReviewDate" />
                ...
        </joined-subclass>

        <joined-subclass extends="Status" name="InServiceStatus">
                <key column="id" on-delete="cascade" />
                <property name="ReviewDate" />
                ...
        </joined-subclass>

        <joined-subclass extends="Status" name="DisposeStatus">
                <key column="id" on-delete="cascade" />
                ...
        </joined-subclass>
</hibernate-mapping>

code:
I want to return all statuses where ReviewDate is between 2 dates.
DetachedCriteria criteria = Repository<AnInterfaceImplementedByStatus>
        .CreateDetachedCriteria()
        .Add(Restrictions.Between("ReviewDate", since, before));

return Repository<AnInterfaceImplementedByStatus>.FindAll(criteria);

Sql:
however the sql produced looks like this
        select  ...
        from    Status s
                        left join PrepareStatus p on s.Id = p.Id
                        left join InServiceStatus i on s.Id = i.Id
                        left join DisposeStatus d on s.Id = d.Id
        where   p.ReviewDate between @p0 and @p1

So only PreparedStatus records are returned.
How would I alter my criteria to generate sql similar to?
        select  ...
        from    Status s
                        left join PrepareStatus p on s.Id = p.Id
                        left join InServiceStatus i on s.Id = i.Id
                        left join DisposeStatus d on s.Id = d.Id
        where   p.ReviewDate between @p0 and @p1
         or             i.ReviewDate between @p0 and @p1


I tried this:
DetachedCriteria criteria = Repository<AnInterfaceImplementedByStatus>
        .CreateDetachedCriteria()
        .CreateAlias("PrepareStatus", "p")
        .CreateAlisa("InServiceStatus", "i")
        .Add(Restrictions.Between("p.ReviewDate", since, before) |
Restrictions.Between("i.ReviewDate", since, before));

return Repository<AnInterfaceImplementedByStatus>.FindAll(criteria);

But NH throws an excpetion: Status does not have a property named
PrepareStatus. Which makes sense since PrepareStatus is an
inheritance, not a property.

thank you in advance.
Jason
--~--~---------~--~----~------------~-------~--~----~
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