Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
2.0
Mapping documents:
<hibernate-mapping auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="MyProject.PaymentRunType, MyProject" table="PaymentRunType" discriminator-value="PaymentRunType">
<id name="ID" access="property" column="ID" type="Int64" unsaved-value="0">
<generator class="hilo">
<param name="max_lo">9</param>
</generator>
</id>
<discriminator column="BureauType" type="string" />
<version name="Version" access="property" column="Version" type="Int32" />
<property name="Name" access="property" type="String">
<column name="Name" length="100"/>
</property>
<many-to-one name="NotificationGroup" access="property" class="MyProject.NotificationGroup, MyProject" column="NotificationGroup" />
<many-to-one name="Template" access="property" class="MyProject.ConfigurationTemplate, MyProject" column="Template" />
<subclass name="MyProject.IndirectPaymentRunType, MyProject" discriminator-value="Indirect">
</subclass>
<subclass name="MyProject.ConfigurationTemplate, MyProject" discriminator-value="DefaultSet">
</subclass>
<subclass name="MyProject.DirectPaymentRunType, MyProject" discriminator-value="Direct">
</subclass>
</class>
</hibernate-mapping>
I'm running against SQL Server.
I need to order the data that I retrieve, the SQL I want is:
Code:
from PAYMENTRUN a
join PAYMENTRUNTYPE b on a.PAYMENTRUNTYPE = b.ID
left outer join PAYMENTRUNTYPE d on b.TEMPLATE = d.ID
join BATCH c on c.ID = a.BATCH
where c.PAYMENTMETHOD = ?
order by isnull(b.NOTIFICATIONGROUP, d.NOTIFICATIONGROUP)
My HQL:
Code:
from PaymentRun as a
join a.PaymentRunType as b
left outer join b.Template as d
join a.Batch as c
where c.PaymentMethod = ?
order by isnull(b.NotificationGroup, d.NotificationGroup)
This results in the SQL:
Code:
from PAYMENTRUN a inner join PAYMENTRUNTYPE b on a.PAYMENTRUNTYPE = b.ID
left outer join PAYMENTRUNTYPE d on b.TEMPLATE = d.ID
inner join BATCH c on a.BATCH = c.ID
where d.BUREAUTYPE = 'DefaultSet'
and c.PAYMENTMETHOD = ?
order by isnull(b.NOTIFICATIONGROUP, d.NOTIFICATIONGROUP)
which obviously negates the left outer join. How can I influence the SQL that is being produced? The fix for the statement is relatively easy, but I have no idea how to control the discriminator column.
Thanks