-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: one-to-one non-lazy loading but Filters Not Applied.
PostPosted: Wed May 27, 2009 2:21 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
We all know that one-to-one associations are non-lazly fetched but during this fetching the filters are not applied.
I debugged hibernate code and found that hibernate finally calls EntityLoader.loadByUniqueKey() method:

public Object loadByUniqueKey(SessionImplementor session, Object key)
throws HibernateException {
return load(session, key, null, null);
}

I can understand that why filters are not applied because all one-to-one association is automatically non-lazyly fetched
and user may not have specified to fetch this associations and hence not enabled corresponding filters on session and also
not provided filter parameters.


For my case it is very important that i always apply filter as in my case if i don't apply filters, it will return me more than one record as i have one-to-one assocition at Domain model level but
same association is one-to-many at database level and by applying filter i make this one-to-many association at database level as
one-to-one association at Domain model.

Is there somehow, i can apply filters always to one-to-one association or better don;t even create a proxy of one-to-one assocaitons that
i have not asked for?


Top
 Profile  
 
 Post subject: Re: one-to-one non-lazy loading but Filters Not Applied.
PostPosted: Wed Jun 24, 2009 12:42 pm 
Newbie

Joined: Wed Jan 23, 2008 7:45 am
Posts: 14
Location: Pune,India
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 &lt;= :asOfDate and END_TIMESTAMP &gt; :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

_________________
Harshal Vaidya


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.