4 Replies Latest reply on Apr 3, 2004 7:04 AM by ebrain13

    IllegalStateException while removing entities in CMR.

    richaosu Newbie

      jboss-3.2.3, java 1.4.2, Informix

      I have CMP entities A, B, C, D as follows:

      A:B is a 1:many relation with directionality from A to B (A gets B)
      A:C is a 1:many relation with directionality from A to B (A gets C)
      C:D is a 1:many relation with directionality from C to D (C gets D)

      I have a SLSB to remove the entities. It iterates over the B collection and performs B.remove(). That works. It then iterates over the D collection and that works too. But when it iterates over the C collection an IllegalStateException is thrown?

      As far as I can see, the only difference between the B collection removal (success) and the C collection removal (failure) is that the C has a CMR to the D collection (which was successfully removed before trying the remove C).

      What is the best way to remove entities when they have CMR? (I would like to remove the entities without using container or RDBMS cascade delete.)

      java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.getIdList(RelationSet.java:66)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.isEmpty(RelationSet.java:80)
      at org.jboss.ejb.plugins.cmp.jdbc.CascadeDeleteStrategy$NoneCascadeDeleteStrategy.removeFromRelations(CascadeDeleteStrategy.java:51)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.removeFromRelations(JDBCCMRFieldBridge.java:312)

        • 1. Re: IllegalStateException while removing entities in CMR.
          Alexey Loubyansky Master

          To reproduce this I would need not only the relationship specification but also some real initial data. Could you please provide it? Thanks.

          • 2. Re: IllegalStateException while removing entities in CMR.
            richaosu Newbie

            I have an example project. It contains the source, dataset, and exploded EAR. It is a self-contained, zipped Eclipse project. How can I send it to you?

            Question: When I look at the getIdList() method of the RelationSet class in package org.jboss.ejb.plugins.cmp.jdbc.bridge, I see the exception is thrown when setHandle[0] is null. IF this is a list of my D entites, then is the exception thrown because I have no D entities (In my example, I remove the D entities before the parant C entity)? If so, how can I remove a C entity?

            As requested here is the sample dataset using Hypersonic SQL:

            create table TABLE_A
            (
             TABLE_A_ID VARCHAR(2) not null,
             VALUE_A1 VARCHAR(16),
             primary key (TABLE_A_ID)
            );
            create table TABLE_B
            (
             TABLE_B_ID VARCHAR(2) not null,
             TABLE_A_ID VARCHAR(2),
             VALUE_B1 VARCHAR(8),
             primary key (TABLE_B_ID)
            );
            create table TABLE_C
            (
             TABLE_C_ID VARCHAR(2) not null,
             TABLE_A_ID VARCHAR(2),
             VALUE_C1 VARCHAR(8),
             primary key (TABLE_C_ID)
            );
            create table TABLE_D
            (
             TABLE_D_ID VARCHAR(2) not null,
             TABLE_C_ID VARCHAR(2),
             VALUE_D1 VARCHAR(8),
             primary key (TABLE_D_ID)
            );
            
            alter table TABLE_B add constraint TABLE_B_FK1 foreign key (TABLE_A_ID) references TABLE_A;
            alter table TABLE_C add constraint TABLE_C_FK1 foreign key (TABLE_A_ID) references TABLE_A;
            alter table TABLE_D add constraint TABLE_D_FK1 foreign key (TABLE_C_ID) references TABLE_C;
            
            insert into TABLE_A values ('a1', 'value_a1');
            insert into TABLE_B values ('b1', 'a1', 'value_b1');
            insert into TABLE_B values ('b2', 'a1', 'value_b2');
            insert into TABLE_C values ('c1', 'a1', 'value_c1');
            insert into TABLE_C values ('c2', 'a1', 'value_c2');
            insert into TABLE_D values ('d1', 'c1', 'value_d1');
            insert into TABLE_D values ('d2', 'c2', 'value_d2');
            insert into TABLE_D values ('d3', 'c2', 'value_d3');
            


            • 3. Re: IllegalStateException while removing entities in CMR.
              Alexey Loubyansky Master

              What is the method code that fails? So far it works for me with these relationships and the data.
              If you have a testcase you can submit a bug report on sf.net/projects/jboss. Thanks.

              • 4. Re: IllegalStateException while removing entities in CMR.
                ebrain13 Newbie

                According to Specs.

                10.3.6.1 Use of the java.util.Collection API to Update Relationships
                The Bean Provider should exercise caution when using an Iterator over a collection in a container-managed relationship. In particular, the Bean Provider should not modify the container-managed collection while the iteration is in progress in any way that causes elements to be added or removed, other than by the java.util.Iterator.remove() method. If elements are added or removed from the underlying container-managed collection used by an iterator other than by the java.util.Iterator.
                remove() method, the container should throw the java.lang.IllegalStateException on the next operation on the iterator
                .


                I would suggest for CMR collections, if you want to modify them while iterating around, make a copy of the CMR Collection and then modify it.