0 Replies Latest reply on Sep 27, 2002 4:26 PM by Kristo Kuusküll

    Collection not updated in one-to-many relationship.

    Kristo Kuusküll Newbie

      Hello,

      I'm using Jboss 3.0.2 on Win2K.

      The following code doesn't work, like i want to:

      // A relationship school-has-many-teachers exists.
      /**
      * @ejb:interface-method
      */
      public void readTeachers(long schoolId){
      try{
      SchoolLocalHome schoolHome = SchoolUtil.getLocalHome();
      SchoolLocal school = schoolHome.findByPrimaryKey(new SchoolPK(new Long(schoolId)));

      // I have'to synchronize this, to avoid the "same collection in different trasanctions" error during highload tests.
      ArrayList teachers;
      Collection teachersTmp = school.getTeachers();
      synchronized (teachersTmp){
      teachers = new ArrayList(teachersTmp);
      }

      m_log.debug("teachers.size()=" + teachers.size());
      Iterator it = teachers.iterator();
      while (it.hasNext()){
      TeacherLocal teacher = (TeacherLocal)it.next();
      m_log.debug("Teacher: " + teacher.getName());
      }
      }
      catch (NamingException e){
      throw new EJBException(e);
      }
      catch (FinderException e){
      throw new EJBException(e);
      }
      }

      The problem is following:
      I
      1. I call the method.
      2. I insert a record manually to the database (Oracle 9i).
      3. I call the method again.

      teachers.size() and collection doesn't change.

      II
      1. I call the method.
      2. I delete a record manually from the database.
      3. I call the method again.

      The following exception is thrown:
      22:08:00,201 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
      javax.ejb.NoSuchObjectLocalException: Entity not found: primaryKey=[.33913.]

      The question is:
      Is there any way to configure the Jboss to refresh the collections, when external database modification occurs, or only way to do it right, is to use finders (schoolHome.findAllTeachers())?


      May the source be with you,
      Kristo.