Filter on List - null elements - very interesting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CatchSandeepVaid
    New Member
    • Apr 2009
    • 15

    Filter on List - null elements - very interesting

    Say i have one-to-many relationship between Product and ProductNames. So Product has a List of ProductNames.


    Actually we are using List for productNames.an d for list, in order to maintain the sequence, it stores the sequence in
    extra seperate column in DB.
    Now say, after applying the filer conditions, 0th, 2nd and 5th element (out of 10 )of the list gets selected..
    Returned list size will of size 6 with 1st,3rd and 4th element as null and 0th,2nd and 5th element properly populated.
    I guess this is done in hibernate for maitaining ordering of List.
    What should i do if i don't want these null elements in the returned List?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Please do not start multiple threads for the same problem.
    Use the removeAll method to remove the nulls.

    Comment

    • CatchSandeepVaid
      New Member
      • Apr 2009
      • 15

      #3
      Actually the problem is not just simple,
      if we consider the entire tree graph(including associations and collections), removing null manulaly from all collections will be a tedious task

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        You said you are getting a List with nulls and you want to remove the nulls. removeAll will remove all the nulls in the list. What is the problem now?

        Comment

        • CatchSandeepVaid
          New Member
          • Apr 2009
          • 15

          #5
          Actually i have written a generic method which accepts the association names and collection names and creates a inner join fetch between them at runtime (using filters also). and i just execute the dynamically generated HQL which returns me root domain object with it's few associations and collections collections populated (which i have asked for)...Now i don;t know which relationship name represented association and which represented collection.. so i can't resume null in a generic way..

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            I am having the code like this ....

            Code:
                    List li = new Vector();
                    li.add(12);
                    li.add(null);
                    li.add(null);
                    li.add(13);
                    li.add(15);
                    li.add(null);
                    List an_li = new Vector();
                    an_li.add(null);
                    li.removeAll(an_li);
                    System.out.println(li.size());
            It's also very interesting ;)

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by CatchSandeepVai d
              Actually i have written a generic method which accepts the association names and collection names and creates a inner join fetch between them at runtime (using filters also). and i just execute the dynamically generated HQL which returns me root domain object with it's few associations and collections collections populated (which i have asked for)...Now i don;t know which relationship name represented association and which represented collection.. so i can't resume null in a generic way..
              I'm sorry to say but this all sounds a bit confused. Better let it return data that you can understand.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by dmjpro
                It's also very interesting ;)
                What's so interesting about it? Its behaviour is exactly as described: it takes the difference of two (multi) sets. Nothing spectacular and nothing surprising.

                kind regards,

                Jos

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by JosAH
                  What's so interesting about it? Its behaviour is exactly as described: it takes the difference of two (multi) sets. Nothing spectacular and nothing surprising.

                  kind regards,

                  Jos
                  No no, i didn't mean what you thought ;)
                  Actually it's according to the title .....

                  Comment

                  Working...