10 Replies Latest reply on Oct 23, 2002 8:52 AM by Le Bris Estelle

    CMR collection problem in jboss-3.0.3

    Le Bris Estelle Newbie

      Hello,

      I have an EJB User which has a relationship with another EJB Profile:
      public abstract class UserBean implements EntityBean {

      private EntityContext context ;

      // Access methods for persistent fields

      public abstract Integer getId() ;
      public abstract void setId(Integer id) ;

      // Access methods for relationship fields

      public abstract Collection getProfiles() ;
      public abstract void setProfiles(Collection profiles) ;
      ...
      }

      and when I try to access the CMR collection in another class:
      Collection profiles = user.getProfiles() ;

      I have this error:
      java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created

      I read someone who says that the bug was in Jboss3.01RC1
      and fixed in CVS but it seems to be not fixed in jboss3.0.3.

      Iris

        • 1. Re: CMR collection problem in jboss-3.0.3
          Alexey Loubyansky Master

          Are you sure this line
          Collection profiles = user.getProfiles();
          throws the excpetion? Post the other code that follows this line. Note, further, profiles collection must be used in the same transaction in which the line with getProfiles() was executed.

          • 2. Re: CMR collection problem in jboss-3.0.3
            Le Bris Estelle Newbie

            I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
            the code that follows, and the exception is not thrown if
            I comment the line user.getProfiles().

            And I use the collection in the same method that user.getProfiles() ; :

            public Enumeration members() {
            System.out.println("Call to members of ProfilesGroup") ;
            try {
            Collection tmp = userHome.findByName(userName) ;
            if ( tmp == null || tmp.isEmpty() )
            return null ;
            User user = (User)tmp.iterator().next() ;
            System.out.println("User: "+user.getName()) ;
            Collection profiles = user.getProfiles() ;
            ArrayList principals = new ArrayList() ;
            Iterator it = profiles.iterator();
            for (; it.hasNext();) {
            Profile profile = (Profile)it.next() ;
            System.out.println("profil: "+profile.getTitle()) ;
            principals.add(new MyPrincipal(profile.getTitle())) ;
            }
            return Collections.enumeration(principals) ;
            } catch (FinderException find) {
            System.err.println("FinderException") ;
            return null ;
            } catch (Exception e) {
            e.printStackTrace() ; // to see the exception about the CMR
            return null ;
            }
            }

            (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

            thanks for ideas.

            Iris

            • 3. Re: CMR collection problem in jboss-3.0.3
              Le Bris Estelle Newbie

              I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
              the code that follows, and the exception is not thrown if
              I comment the line user.getProfiles().

              And I use the collection in the same method that user.getProfiles() ; :

              public Enumeration members() {
              System.out.println("Call to members of ProfilesGroup") ;
              try {
              Collection tmp = userHome.findByName(userName) ;
              if ( tmp == null || tmp.isEmpty() )
              return null ;
              User user = (User)tmp.iterator().next() ;
              System.out.println("User: "+user.getName()) ;
              Collection profiles = user.getProfiles() ;
              ArrayList principals = new ArrayList() ;
              Iterator it = profiles.iterator();
              for (; it.hasNext();) {
              Profile profile = (Profile)it.next() ;
              System.out.println("profil: "+profile.getTitle()) ;
              principals.add(new MyPrincipal(profile.getTitle())) ;
              }
              return Collections.enumeration(principals) ;
              } catch (FinderException find) {
              System.err.println("FinderException") ;
              return null ;
              } catch (Exception e) {
              e.printStackTrace() ; // to see the exception about the CMR
              return null ;
              }
              }

              (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

              thanks for ideas.

              Iris

              • 4. Re: CMR collection problem in jboss-3.0.3
                Le Bris Estelle Newbie

                I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
                the code that follows, and the exception is not thrown if
                I comment the line user.getProfiles().

                And I use the collection in the same method that user.getProfiles() ; :

                public Enumeration members() {
                System.out.println("Call to members of ProfilesGroup") ;
                try {
                Collection tmp = userHome.findByName(userName) ;
                if ( tmp == null || tmp.isEmpty() )
                return null ;
                User user = (User)tmp.iterator().next() ;
                System.out.println("User: "+user.getName()) ;
                Collection profiles = user.getProfiles() ;
                ArrayList principals = new ArrayList() ;
                Iterator it = profiles.iterator();
                for (; it.hasNext();) {
                Profile profile = (Profile)it.next() ;
                System.out.println("profil: "+profile.getTitle()) ;
                principals.add(new MyPrincipal(profile.getTitle())) ;
                }
                return Collections.enumeration(principals) ;
                } catch (FinderException find) {
                System.err.println("FinderException") ;
                return null ;
                } catch (Exception e) {
                e.printStackTrace() ; // to see the exception about the CMR
                return null ;
                }
                }

                (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

                thanks for ideas.

                Iris

                • 5. Re: CMR collection problem in jboss-3.0.3
                  Le Bris Estelle Newbie

                  I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
                  the code that follows, and the exception is not thrown if
                  I comment the line user.getProfiles().

                  And I use the collection in the same method that user.getProfiles() ; :

                  public Enumeration members() {
                  System.out.println("Call to members of ProfilesGroup") ;
                  try {
                  Collection tmp = userHome.findByName(userName) ;
                  if ( tmp == null || tmp.isEmpty() )
                  return null ;
                  User user = (User)tmp.iterator().next() ;
                  System.out.println("User: "+user.getName()) ;
                  Collection profiles = user.getProfiles() ;
                  ArrayList principals = new ArrayList() ;
                  Iterator it = profiles.iterator();
                  for (; it.hasNext();) {
                  Profile profile = (Profile)it.next() ;
                  System.out.println("profil: "+profile.getTitle()) ;
                  principals.add(new MyPrincipal(profile.getTitle())) ;
                  }
                  return Collections.enumeration(principals) ;
                  } catch (FinderException find) {
                  System.err.println("FinderException") ;
                  return null ;
                  } catch (Exception e) {
                  e.printStackTrace() ; // to see the exception about the CMR
                  return null ;
                  }
                  }

                  (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

                  thanks for ideas.

                  Iris

                  • 6. Re: CMR collection problem in jboss-3.0.3
                    Le Bris Estelle Newbie

                    I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
                    the code that follows, and the exception is not thrown if
                    I comment the line user.getProfiles().

                    And I use the collection in the same method that user.getProfiles() ; :

                    public Enumeration members() {
                    System.out.println("Call to members of ProfilesGroup") ;
                    try {
                    Collection tmp = userHome.findByName(userName) ;
                    if ( tmp == null || tmp.isEmpty() )
                    return null ;
                    User user = (User)tmp.iterator().next() ;
                    System.out.println("User: "+user.getName()) ;
                    Collection profiles = user.getProfiles() ;
                    ArrayList principals = new ArrayList() ;
                    Iterator it = profiles.iterator();
                    for (; it.hasNext();) {
                    Profile profile = (Profile)it.next() ;
                    System.out.println("profil: "+profile.getTitle()) ;
                    principals.add(new MyPrincipal(profile.getTitle())) ;
                    }
                    return Collections.enumeration(principals) ;
                    } catch (FinderException find) {
                    System.err.println("FinderException") ;
                    return null ;
                    } catch (Exception e) {
                    e.printStackTrace() ; // to see the exception about the CMR
                    return null ;
                    }
                    }

                    (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

                    thanks for ideas.

                    Iris

                    • 7. Re: CMR collection problem in jboss-3.0.3
                      Le Bris Estelle Newbie

                      I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
                      the code that follows, and the exception is not thrown if
                      I comment the line user.getProfiles().

                      And I use the collection in the same method that user.getProfiles() ; :

                      public Enumeration members() {
                      System.out.println("Call to members of ProfilesGroup") ;
                      try {
                      Collection tmp = userHome.findByName(userName) ;
                      if ( tmp == null || tmp.isEmpty() )
                      return null ;
                      User user = (User)tmp.iterator().next() ;
                      System.out.println("User: "+user.getName()) ;
                      Collection profiles = user.getProfiles() ;
                      ArrayList principals = new ArrayList() ;
                      Iterator it = profiles.iterator();
                      for (; it.hasNext();) {
                      Profile profile = (Profile)it.next() ;
                      System.out.println("profil: "+profile.getTitle()) ;
                      principals.add(new MyPrincipal(profile.getTitle())) ;
                      }
                      return Collections.enumeration(principals) ;
                      } catch (FinderException find) {
                      System.err.println("FinderException") ;
                      return null ;
                      } catch (Exception e) {
                      e.printStackTrace() ; // to see the exception about the CMR
                      return null ;
                      }
                      }

                      (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

                      thanks for ideas.

                      Iris

                      • 8. Re: CMR collection problem in jboss-3.0.3
                        Le Bris Estelle Newbie

                        I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
                        the code that follows, and the exception is not thrown if
                        I comment the line user.getProfiles().

                        And I use the collection in the same method that user.getProfiles() ; :

                        public Enumeration members() {
                        System.out.println("Call to members of ProfilesGroup") ;
                        try {
                        Collection tmp = userHome.findByName(userName) ;
                        if ( tmp == null || tmp.isEmpty() )
                        return null ;
                        User user = (User)tmp.iterator().next() ;
                        System.out.println("User: "+user.getName()) ;
                        Collection profiles = user.getProfiles() ;
                        ArrayList principals = new ArrayList() ;
                        Iterator it = profiles.iterator();
                        for (; it.hasNext();) {
                        Profile profile = (Profile)it.next() ;
                        System.out.println("profil: "+profile.getTitle()) ;
                        principals.add(new MyPrincipal(profile.getTitle())) ;
                        }
                        return Collections.enumeration(principals) ;
                        } catch (FinderException find) {
                        System.err.println("FinderException") ;
                        return null ;
                        } catch (Exception e) {
                        e.printStackTrace() ; // to see the exception about the CMR
                        return null ;
                        }
                        }

                        (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

                        thanks for ideas.

                        Iris

                        • 9. Re: CMR collection problem in jboss-3.0.3
                          Le Bris Estelle Newbie

                          I'm sure it is the line user.getProfiles() that throws the exception because the exception still when I comment
                          the code that follows, and the exception is not thrown if
                          I comment the line user.getProfiles().

                          And I use the collection in the same method that user.getProfiles() ; :

                          public Enumeration members() {
                          System.out.println("Call to members of ProfilesGroup") ;
                          try {
                          Collection tmp = userHome.findByName(userName) ;
                          if ( tmp == null || tmp.isEmpty() )
                          return null ;
                          User user = (User)tmp.iterator().next() ;
                          System.out.println("User: "+user.getName()) ;
                          Collection profiles = user.getProfiles() ;
                          ArrayList principals = new ArrayList() ;
                          Iterator it = profiles.iterator();
                          for (; it.hasNext();) {
                          Profile profile = (Profile)it.next() ;
                          System.out.println("profil: "+profile.getTitle()) ;
                          principals.add(new MyPrincipal(profile.getTitle())) ;
                          }
                          return Collections.enumeration(principals) ;
                          } catch (FinderException find) {
                          System.err.println("FinderException") ;
                          return null ;
                          } catch (Exception e) {
                          e.printStackTrace() ; // to see the exception about the CMR
                          return null ;
                          }
                          }

                          (this exception is when I use jboss3.0.3 but not when I use jboss3.0.0)

                          thanks for ideas.

                          Iris

                          • 10. Re: CMR collection problem in jboss-3.0.3
                            Le Bris Estelle Newbie

                            Excuse me,

                            It seems I had a problem with the submit "Post Message".

                            Iris