3 Replies Latest reply on Jun 12, 2004 3:28 AM by bentins

    IllegalStateException Help!


      I'm getting the dreaded java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created

      I've tried using user transactions, making the transaction required in the bean, nothing seems to work. I'm running 3.0.8.

      Anyone have an ideas? I'm really stuck.

        • 1. Re: IllegalStateException Help!

          Post your code snippet, not just saying IT NOT WORK.

          • 2. Re: IllegalStateException Help!

            i think you are geeting a collection of localhome objects and then getting an iterator and you are running a while loop over that within which you are type casting the object to the secondary localhome object and then you are applying remove over that, but you do like this

            get the collection
            get the iterator
            apply remove method on iterator

            i too have a same problem and after doing like this it worked fine try this.
            with regards

            • 3. Re: IllegalStateException Help!

              Don't know if it helps but consider this explanation:

              When you call upon an entity with some kind of getCollection and receive a collection of locals of another bean you performed a transaction. If you have not opened a transaction outside this call context, say in a session bean, you performed this get in it's own transaction which ended when you finished the get. So now when you try to manipulate this collection it is already outside the transaction context. So, if you make your entity transaction requiered it's not enough, it only states that when you call upon the entity you use a transaction, a transaction is opened for each call separatly.

              If you don't want this behavior (and obviously you don't) your best bet is to open a transaction before you manipulate the entity bean and its relations, thus when operating within transaction context the container will not open a new one, and only close it after you finsihed everything you want to do.

              The easiest way to do this is to use a session bean facade. Open the transaction on the session bean which will do all the work on the entities and only when it's method is done it will close the transaction.