• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with querying and one to many relationship..

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following mappings in my hibernate hbm.xml file (this cannot be changed, the table structure has been decided by the DBA):


We are passing these Postcode objects through to struts instead of having data transfer objects, this is read only data - the application will never modify any postcode/suburb information.

My problem is that I need a query that gives the same result as the following two queries:

but instead of returning Suburb objects and Postcode objects, only returns Postcode objects. As you can see, the first query will return Suburb objects as I am searching on the nzTownCity or nzSuburb columns because the suburbRequiredFlag is set to 'Y' on the Postcode.

I know this seems fairly complicated but if there is a way that I can get only Postcode objects with the matching Suburb objects (instead of all the Suburb objects that are bound to a Postcode because of the one-to-many relationship) then that would be great.

Thanks in advance,
Annie



 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if I understood well but, have you tried



and since it's ManyToOne you should be able to access Postcode object

reply
    Bookmark Topic Watch Topic
  • New Topic