3 Replies Latest reply on Nov 8, 2006 4:58 AM by ben.wang

    Cross-reference problem

    finnam

      Hi guys!

      We've met a problem with JBoss cache and we don't know if it's a bug or usage problem.
      We have an annotated User class wich has an ArrayList buddies property. We put two instances of User class to the cache and each instance has a reference to another one from the buddies list. The code is like this:

      User user1 = new User();
      User user2 = new User();
      cache.putObject(user1.getFqn(), user1);
      cache.putObject(user2.getFqn(), user2);
      //skipped
      user1.getBuddies().add(user2);
      //skipped
      user2.getBuddies().add(user1);
      


      On some event we are removing user1 from the cache:
      user2.getBuddies().remove(user1);
      cache.removeObject(user1.getFqn());
      


      And then we are putting it again:
      cache.putObject(user1.getFqn(), user1);
      user2.getBuddies().add(user1);
      

      This last line of code throws IllegalStateException with the following message:
      AopInstance.incrementRefCount: source fgn /users/user1 is already present.

      After a small debugging we added following befor removing user1 from cache:
      user1.getBuddies().clean();

      And all the problems are gone.

      So, should we really remove all the references to the cached objects from user1 before removing it from the cache or it's a problem of illegal usage?