2 Replies Latest reply on Jun 12, 2006 2:59 AM by Ritchie Koh

    don't want the LazyInitializationExceptoin

    Ritchie Koh Newbie

      Dear.

      When I need not get the children collection, there is occurred the LazyInitializationException.

      Board has recursive relationship.
      I want to get the Board data only as one object and his children object, but there are many recursive relationship object.
      There has grandchildren object with recursive relationship, not I want to get the grandchildren object, but I want to get just the object and his children object.
      but when one child object to get his child object(grandson object of root object), there occurs the LazyInitializationException.
      So I did coded as below, but there still occurrs the LayInitializationException.

       try {
      
       for(Board childBoard : childBoards) {
       str.append(childBoard.toXML());
       }
      
       } catch (LazyInitializationException e) {
       //do not want to stdout the error message
       }
      


      How do I code to not stdout the LazyInitializationException message.

      # Ritchie.

        • 1. Re: don't want the LazyInitializationExceptoin
          andy Newbie

          not sure if I got it right, but if your parent or child relations are annotated with "lazy", you must do all calls to parent and children in an entity context (running transaction). this is normally in a SLSB or SFSB. maybe you should post your Board bean code here ...

          • 2. Re: don't want the LazyInitializationExceptoin
            Ritchie Koh Newbie

            Thanks.

            I did Lazy annotation in the relationship as below.

             @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentBoard")
             public Collection<Board> getChildBoards() {
             return childBoards;
             }
            
             public void setChildBoards(Collection<Board> childBoards) {
             this.childBoards = childBoards;
             }
            


            And to obtain the root object and his children object , I call a method as below.
            So I can get just the Object and his children object.

             public void obtainOneLevelChild() {
            
             childBoards.size();
            
             }
            


            I need not occur LazyInitializationException message in the console or log file

            Regards.