Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

One-To-One Filter Applied, Non-Lazy Fetch Problem

Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose i have one-to-one association between Product and ProductBasic. and we have applied filter on ProductBasic Class.
I have applied this filter as in Java side we have one-to-one relationship between Product and ProductBasic BUT at database side
we have one-to-many relationship between PRODUCT and PRODUCTBASIC. and we apply a condition (STARTTIME < CURRETTIME < ENDTIME)
while fetching PRODUCTBASIC, and this will always give me one record out of many.
So i have put this condition as filter in ProductBasic class.

In current hibernate, one-to-one associations are always non-lazily fetched. Moreover it doesn't apply filter conditions.
I understand that it can;t apply filter condition as some filter parameter must be provided at runtime and
user may not provide them (as he is not asking for ProductBasic)... Also in this case, proper proxy can't be created as
until we apply the filter criteria, we won't get one ProductBasic row (among many)..

I think hibernate code should be changed so that if a filter is declared on the associated class (ProductBasic in our case),
hibernate should return null for ProductBasic.
author and cow tipper
Posts: 5000
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The association is fetched in an eagar fashion by default, but you can change it to lazy.

-Cameron McKenzie
Straws are for suckers. Now suck on this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic