facebook

[Closed] how to exclude elements with empty collection?

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #269415 Reply

    predbit
    Member

    Hi everybody..

    I am using hibernate and oracle db.

    I have a table “A” and a table “B”, with a many-to-many association.

    I have to retrieve from DB informations about objects from table “A” and the related objects from table “B”, ecluding those objects from table “A” which don’t have associated any element of “B”.

    Currently I query for objects in table “A”, then for any element retrieved I read the collection of associated “B” objects.

    Maybe it’s a trivial question, but how can I exclude from the result set those elements of table “A” for which the collection of “B” elements is empty?

    Thanks in advance for your help.

    #269464 Reply

    predbit
    Member

    Solved..
    the solution was actually trivial.. 😳

    Please close.

    #269480 Reply

    Riyad Kalla
    Member

    predbit,
    Could you follow up for other folks that may have the same problem with how you fixed this?

    #269687 Reply

    predbit
    Member

    sure… I did not post the solution because it was very very simple…

    HQL can check for elements with “not empty” collections as follows:

    from table as T where not (T.collection is empty)
Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: [Closed] how to exclude elements with empty collection?

You must be logged in to post in the forum log in