This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Querying on Child Objects

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,
I have a problem. I have a parent class named 'Trade' and each trade and many child objects named 'TradeEvents'. I want to use a Criteria object and create a query such that I can add restrictions on both objects. For eg. I want to get trades who has status as 'O' and get it's corresponding trade events that has notional greater than 100.

so i use a critiia like this:

Criteria criteria = HibernateSessionFactory.getSession().createCriteria(Trades.class);
criteria.add(Restrictions.eq("status","O"));
criteria.createCriteria("tradeEvents").add(Restrictions.lt("notional", new Double(100)));
List list = criteria.list();


However, when I execute the criteria it returns me trades that are open which is fine but the child object(trade events) that I obtain has all the trade events belonging to that trade even though it's notional is greater than 100. So the child objects are not being restricted. How can I achieve this?
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not an expert, I think it should look like following:
 
Salil Surendran
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code is correct but it produces the same result. In you code you also need to add an alias to tradeEvents to make it work.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic