CMR and ConcurrentModificationException - Weblogic

This is a discussion on CMR and ConcurrentModificationException - Weblogic ; Hello, We are experiencing ConcurrentModificationException when deleting an entity bean that was obtained via the collection from a CMR field. Understanding fully what rules apply to the use of the iterator and modifying the collection while operating on the iterator, ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: CMR and ConcurrentModificationException

  1. CMR and ConcurrentModificationException


    Hello,

    We are experiencing ConcurrentModificationException when deleting an entity bean
    that was obtained via the collection from a CMR field. Understanding fully what
    rules apply to the use of the iterator and modifying the collection while operating
    on the iterator, we receive the error when performing the following:

    Collection children = ParentEJB.getChildren();
    for (Iterator itr = children.iterator(); itr.hasNext() {
    ChildEJB child = (ChildEJB)itr.next();
    //perform some check on the child attributes not modifying the collection....
    if (some condition) {
    child.remove();
    //itr.remove(); //I believe this is unnecessary when removing the bean...
    }
    }

    The exception happens at the call to itr.next().

    The above scenario is carried out by a stateless session bean. In a JUnit test
    case that uses the session bean, we test all the functions on the session bean,
    one of which performs the above logic. It seems that when all the test cases
    are run in one sweep, we get the ConcurrentModificationException and it isn't
    consistent. The test adds, updates, deletes children, deletes parent in separate
    transactions.

    Is it possible that the app server is doing something with the collection at the
    time we try to delete? How can we ensure that the app server doesn't hold reference
    to the iterator or modify the collection as a result of other operations on the
    same ParentEJB? I tried both Optimistic and Database concurrency.

    We are using WLS 8.1 SP1.

    I tried to explain without a huge stack trace or code listing. Does this make
    sense to anyone?

    Thanks,

    Mike

  2. Re: CMR and ConcurrentModificationException


    Modify the itr.hasNext() method call.
    while (itr.hasNext()) {itr.next(); }

    "Mike Wright" wrote:
    >
    >Hello,
    >
    >We are experiencing ConcurrentModificationException when deleting an
    >entity bean
    >that was obtained via the collection from a CMR field. Understanding
    >fully what
    >rules apply to the use of the iterator and modifying the collection while
    >operating
    >on the iterator, we receive the error when performing the following:
    >
    >Collection children = ParentEJB.getChildren();
    >for (Iterator itr = children.iterator(); itr.hasNext() {
    > ChildEJB child = (ChildEJB)itr.next();
    > //perform some check on the child attributes not modifying the collection....
    > if (some condition) {
    > child.remove();
    > //itr.remove(); //I believe this is unnecessary when removing
    >the bean...
    > }
    >}
    >
    >The exception happens at the call to itr.next().
    >
    >The above scenario is carried out by a stateless session bean. In a
    >JUnit test
    >case that uses the session bean, we test all the functions on the session
    >bean,
    >one of which performs the above logic. It seems that when all the test
    >cases
    >are run in one sweep, we get the ConcurrentModificationException and
    >it isn't
    >consistent. The test adds, updates, deletes children, deletes parent
    >in separate
    >transactions.
    >
    >Is it possible that the app server is doing something with the collection
    >at the
    >time we try to delete? How can we ensure that the app server doesn't
    >hold reference
    >to the iterator or modify the collection as a result of other operations
    >on the
    >same ParentEJB? I tried both Optimistic and Database concurrency.
    >
    >We are using WLS 8.1 SP1.
    >
    >I tried to explain without a huge stack trace or code listing. Does
    >this make
    >sense to anyone?
    >
    >Thanks,
    >
    >Mike



  3. Re: CMR and ConcurrentModificationException


    I'm not sure I understand the suugestion...

    for (Iterator itr = children.iterator(); itr.hasNext() {
    ChildEJB child = (ChildEJB)itr.next();
    }

    is the same as:

    Iterator itr = children.iterator();

    while(itr.hasNext()) {

    ChildEJB child = (ChildEJB)itr.next();
    }



    "Deepak Vohra" wrote:
    >
    >Modify the itr.hasNext() method call.
    >while (itr.hasNext()) {itr.next(); }
    >
    >"Mike Wright" wrote:
    >>
    >>Hello,
    >>
    >>We are experiencing ConcurrentModificationException when deleting an
    >>entity bean
    >>that was obtained via the collection from a CMR field. Understanding
    >>fully what
    >>rules apply to the use of the iterator and modifying the collection

    >while
    >>operating
    >>on the iterator, we receive the error when performing the following:
    >>
    >>Collection children = ParentEJB.getChildren();
    >>for (Iterator itr = children.iterator(); itr.hasNext() {
    >> ChildEJB child = (ChildEJB)itr.next();
    >> //perform some check on the child attributes not modifying the collection....
    >> if (some condition) {
    >> child.remove();
    >> //itr.remove(); //I believe this is unnecessary when removing
    >>the bean...
    >> }
    >>}
    >>
    >>The exception happens at the call to itr.next().
    >>
    >>The above scenario is carried out by a stateless session bean. In a
    >>JUnit test
    >>case that uses the session bean, we test all the functions on the session
    >>bean,
    >>one of which performs the above logic. It seems that when all the test
    >>cases
    >>are run in one sweep, we get the ConcurrentModificationException and
    >>it isn't
    >>consistent. The test adds, updates, deletes children, deletes parent
    >>in separate
    >>transactions.
    >>
    >>Is it possible that the app server is doing something with the collection
    >>at the
    >>time we try to delete? How can we ensure that the app server doesn't
    >>hold reference
    >>to the iterator or modify the collection as a result of other operations
    >>on the
    >>same ParentEJB? I tried both Optimistic and Database concurrency.
    >>
    >>We are using WLS 8.1 SP1.
    >>
    >>I tried to explain without a huge stack trace or code listing. Does
    >>this make
    >>sense to anyone?
    >>
    >>Thanks,
    >>
    >>Mike

    >



  4. Re: CMR and ConcurrentModificationException

    Was this ever answered? I am having the exact same problem (using
    weblogic 6.1).
    When trying to remove entity beans returned from a finder method in a
    collection, should I call the remove() method of the iterator, or of the
    entity? When calling remove() on the local interface of the entity bean,
    I get the 'ConcurrentModificationException' exception. When calling
    remove() on the iterator, I get a SQLException because it seems to be
    trying to update the row with a NULL in the foreign key field, which is
    defined as NOT NULL because it is on the 'Many' side of the 1-Many
    relationship.

    Thanks,
    - Don

    Mike Wright wrote:
    > I'm not sure I understand the suugestion...
    >
    > for (Iterator itr = children.iterator(); itr.hasNext() {
    > ChildEJB child = (ChildEJB)itr.next();
    > }
    >
    > is the same as:
    >
    > Iterator itr = children.iterator();
    >
    > while(itr.hasNext()) {
    >
    > ChildEJB child = (ChildEJB)itr.next();
    > }
    >
    >
    >
    > "Deepak Vohra" wrote:
    >
    >>Modify the itr.hasNext() method call.
    >>while (itr.hasNext()) {itr.next(); }
    >>
    >>"Mike Wright" wrote:
    >>
    >>>Hello,
    >>>
    >>>We are experiencing ConcurrentModificationException when deleting an
    >>>entity bean
    >>>that was obtained via the collection from a CMR field. Understanding
    >>>fully what
    >>>rules apply to the use of the iterator and modifying the collection

    >>
    >>while
    >>
    >>>operating
    >>>on the iterator, we receive the error when performing the following:
    >>>
    >>>Collection children = ParentEJB.getChildren();
    >>>for (Iterator itr = children.iterator(); itr.hasNext() {
    >>> ChildEJB child = (ChildEJB)itr.next();
    >>> //perform some check on the child attributes not modifying the collection....
    >>> if (some condition) {
    >>> child.remove();
    >>> //itr.remove(); //I believe this is unnecessary when removing
    >>>the bean...
    >>> }
    >>>}
    >>>
    >>>The exception happens at the call to itr.next().
    >>>
    >>>The above scenario is carried out by a stateless session bean. In a
    >>>JUnit test
    >>>case that uses the session bean, we test all the functions on the session
    >>>bean,
    >>>one of which performs the above logic. It seems that when all the test
    >>>cases
    >>>are run in one sweep, we get the ConcurrentModificationException and
    >>>it isn't
    >>>consistent. The test adds, updates, deletes children, deletes parent
    >>>in separate
    >>>transactions.
    >>>
    >>>Is it possible that the app server is doing something with the collection
    >>>at the
    >>>time we try to delete? How can we ensure that the app server doesn't
    >>>hold reference
    >>>to the iterator or modify the collection as a result of other operations
    >>>on the
    >>>same ParentEJB? I tried both Optimistic and Database concurrency.
    >>>
    >>>We are using WLS 8.1 SP1.
    >>>
    >>>I tried to explain without a huge stack trace or code listing. Does
    >>>this make
    >>>sense to anyone?
    >>>
    >>>Thanks,
    >>>
    >>>Mike

    >>

    >


+ Reply to Thread