• 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

Querying: restricting collection based on parent?

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a database with tables contact and address I would like to find the housemates of a given contact.
The following HQL query is a good start:

That is, it yields a collection of contacts, each of which has a single address, each of which has a collection of all contacts living at that address. As expected, each contact lists itself as housemate, which is not what I want. Let’s try a refinement:

Here, the ‘where’ clause is ignored, as per the Hibernate documentation (Section 14.3):

   A fetch join does not usually need to assign an alias, because the associated objects should not be used in the where clause (or any other clause). The associated objects are also not returned directly in the query results. Instead, they may be accessed via the parent object. The only reason you might need an alias is if you are recursively join fetching a further collection

The generated SQL works as expected, though.

Is there any way to get this to work, other than by manually populating the housemates collection?
It means our mission is in jeapordy! Quick, read this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic