I have the following mapping:
<class name="Customer">
<!-- actually one-to-one for all intents and purposes-->
<many-to-one name="specialProperty" class="SpecialProperty" cascade="all" not-found="ignore" insert="false" update="false" column="id" unique="true"/>
</class
<class name="SpecialProperty" lazy="false">
<id name="id" column="customer_id">
<generator class="foreign">
<param name="property">customer</param>
</generator>
<one-to-one name="customer" class="Customer" constrained="true"></one-to-one>
</class>
Using this mapping, customer.specialProperty is null when there is no entry for the particular customer in the special_properties table. (using regular one-to-one mapping results in specialProperty holding a proxy object, so I can't test for null) So in code I can simply do customer.specialProperty == null to see if a Customer has a SpecialProperty.
I'm trying to write a query that will return all Customers who have a non-null SpecialProperty, and another query that will return all Customers who have a null SpecialProperty.
I can get Customers who have a non-null SpecialProperty like so:
from Customer customer inner join customer.specialProperty
However, I can't get customers who don't have a SpecialProperty (e.g. customer.specialProperty == null)
I've tried a few things. Basically what I want is something like
from Customer customer where customer.specialProperty is null
but this generates sql that tests for customer.id being null for whatever reason.
Suggestions?