Hi,
I also have a similar situation. I have a class DealHistory where I have defined a Filter like this:
Code:
DealHistory.hbm.xml
<filter name="asOfDateFilter" condition="START_TIMESTAMP <= :asOfDate and END_TIMESTAMP > :asOfDate"></filter>
The definition of the filter reads like this:
Code:
DealHistory.hbm.xml
<filter-def name="asOfDateFilter">
<filter-param name="asOfDate" type="timestamp"/>
</filter-def>
Now my DealHistory class has a one-to-one relationship with a class called DealSynopsis. Its mapped like this:
Code:
DealHistory.hbm.xml
<one-to-one name="dealSynopsis" class="com.ms.itlnc.dms.data.history.DealSynopsisHistory"
cascade="save-update"/>
The DealSynopsis class also defines the exact same filter since I need this filter to be applied on the DealSynopsis class as well. Here is the definition:
Code:
DealSynopsis.hbm.xml
<filter-def name="asOfDateFilterDS">
<filter-param name="asOfDate" type="timestamp"/>
</filter-def>
I am enabling these both filters before I query like this:
Code:
session.enableFilter("asOfDateFilter").setParameter("asOfDate", asOfDate);
session.enableFilter("asOfDateFilterDS").setParameter("asOfDate", asOfDate);
And the query I am firing looks like this:
Code:
Query qry = session.createQuery("from DealHistory dh" +
" left join fetch dh.dealSynopsis ds" +
" where dh.dealKey = :dealKey" );
qry.setParameter("dealKey", dealKey);
I am expecting that when the query is executed the filter asOfDateFilter on DealHistory as well as the filter asOfDateFilterDS on DealSynopsis should both get applied. However, this doesn't happen. The query only applies the filter to DealHistory.
Is there any way to get this applied to one-to-one relationship as well ? I can apply a where condition in the query and get this working, but I have several objects in the hierarchy which are in a one-to-one relationship. I don't want to apply a where condition in the query for all of them. A filter would be great.
-Harshal