Hello,
I have 2 classes

ClassA mapped as:

<class name="ClassA" table="ClassA" lazy="true" where="Validity=1">

                <id name="Id">
                        <column name="idClassA"/>
                        <generator class="native"/>
                </id>


                <bag name="ClassBs" cascade="save-update" lazy="true"
where="Validity=1" order-by="DatTim asc">
                        <key column="idClassA"/>
                        <one-to-many class="ClassB"/>
                </bag>
...
</class>

ClassB mapped as:

<class name="ClassB" table="ClassB" lazy="true" where="Validity=1">

                <id name="Id">
                        <column name="idClassB"/>
                        <generator class="native"/>
                </id>

                <many-to-one name="ClassA"
                                                                 class="ClassA"
                                                                 
column="idClassB"
                                                                 cascade="none" 
/>
...
</class>

The problem is, that when I want nHibernate to fetch ClassA's using
subqueries - something like:
targetObjects.Add(Subqueries.PropertyIn("Id",
 
DetachedCriteria.For(ClassA).Add(Subqueries.PropertyNotIn("Id",
                             DetachedCriteria.For(ClassA).Add(--join
ClassB and add criteria for ClassB--) ))
) ).SetMaxResults(maxCount);

I expect I get SQL query like
 SELECT TOP 100 * FROM ClassA JOIN ClassB WHERE ClassA in (
                SELECT DISTINCT idClassA FROM ClassA WHERE idClassA
not in (
                              SELECT idClassA FROM ClassA LEFT JOIN
ClassB WHERE ClassB.param=x)
                )) order by ClassB.DatTim asc

but what I get is:
 SELECT TOP 100 * FROM ClassA JOIN ClassB WHERE ClassA in (
                SELECT DISTINCT idClassA FROM ClassA JOIN ClassB WHERE
idClassA not in (
                              SELECT idClassA FROM ClassA LEFT JOIN
ClassB WHERE ClassB.param=x)
                ) order by ClassB.DatTim asc )

which throws an expception, that Order By cannot be used in subqueries
without using TOP.

So my question is whether there is any way how to disable order-by
parameter from mapping when needed, or if there is any onther way, how
to construct the criteria...
The order-by in mapping is used because I want to fetch the list of
ClassB sorted...

Thank you for any suggestions.


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