Hibernate request for an object based on whether the bound property of the object is null?
I have the following display:
<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, client.specialProperty is null when there is no entry for a specific client in the special_properties table. (using regular one-to-one matching on the specialProperty containing the proxy so I can't check for null). So in the code, I can just do client.specialProperty == null to see if the Client has a SpecialProperty.
I am trying to write a query that will return all Clients that have a non-null SpecialProperty and another query that will return all Clients that have a null SpecialProperty.
I can get Clients that have a non-null SpecialProperty like:
from Customer customer inner join customer.specialProperty
However, I cannot get clients that do not have a SpecialProperty (e.g. customer.specialProperty == null)
I have tried several things. Basically I want something like
from Customer customer where customer.specialProperty is null
but this generates sql which checks that customer.id is null for whatever reason.
Suggestions?
a source to share