3 Replies Latest reply on Aug 29, 2007 3:28 PM by wquraishi

    help needed! error

    destiny84

      Hello @ all...
      I really need some more help :S ...

      I have a class Employee with a function :

      public Set<Project> getProjects() {
       return this.projects;
       }
      


      Now I have another class, in which I have a function with the following code:
      Set<Project> set = user.getProjects();
      SelectItem[] list = new SelectItem[set.size()];
      

      the user is of instance employee and does actually exist, because when I call user.getName() (which is of course another function from employee) , it works fine.
      Now the code above gives an error:

      ERROR [org.hibernate.LazyInitializationException] failed to lazily initialize a collection of role: er.Employee.projects, no session or session was closed
      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: er.Employee.projects, no session or session was closed
      


      Now as soon as I remove the call to set.size() , I do not get that error anymore.

      Any suggestions?

      Thanks!

        • 1. Re: help needed! error
          destiny84

          Err...I was sure I had error: failed to lazily initialize a collection in my topic title ?! ...oh well....sorry bout that

          • 2. Re: help needed! error
            gavin.king

            So, this is a problem in how you are managing your persistence context. Probably it would help to use a Seam-managed conversation-scoped persistence context, but I can't tell since you have not given any information about what you are actually doing...

            • 3. Re: help needed! error
              wquraishi

              One thing I discovered is if you override the toString() method and output the relationships, it'll force the container to load the relationship related fields. I'm thinking it accomplishes the same thing as fetchtype.eager but i've had more luck with this. Plus it works dual fold since I use the toString() method in conjunction with facesMessages to display what the object coming back is.