Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Specify relationship in mapping using some condition not just id's.

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Say i have one-to-many relationship between Product and ProductNames
Product ----> PID (PK)
ProductNames------> PID, USECODE, STARTTIME as composite ID and ENDTIME is another normal column.

Now i want to fetch product with PID='1' and USECODE='100' and STARTTIME < CURRENTTIME < ENDTIME.

CURRENTTIME value will be known at runtime.

How to specify this in mapping and fetch Product & ProductNames using eager fetching?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to specify this in the mapping rather than as a query? Doesn't that limit your model?
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
As currentTime value is only known at runtime, i can;t specify it's value in mapping.

Using Filters, this problem can be resolved. Define filter, attach filter and enable filter. Filter supports specifying positional parameters value at runtime.
but i got 1 problem with filters :
Suppose i have 1 product with id as 100, it has 5 ProductNames..but when we apply filter only 2 productNames remains.

When i use just "inner join fetch" with no filters, it returns me one Product object which contains List of productNames properly
populated.
BUT When i use "select distinct product" and inner join fetch" with filter, it returns one product populated with productNames
list which contains 3 elements viz. null, first filtered productName, second filtered productName..

Why productNames list contains the first element as null? This seems to be a bug..
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic