Cannot remove session bean within a transaction

Discussions

EJB programming & troubleshooting: Cannot remove session bean within a transaction

  1. Cannot remove session bean within a transaction (1 messages)

    I'm running into a problem in VAJ 3.5 EE.

    I'm getting an javax.ejb.RemoveException: Cannot remove session bean within a transaction when I attempt to
    remove another session bean from a session bean. I was wondering if anyone can point to the EJB specs that states
    that this is not possible.

    I have a stateless session bean A, which in a method call, creates a stateless session bean B. At the end of the
    method, I try to remove EJB B to clean up, but get get the above exception. Both A and B are container managed
    transaction that have the transaction attribute TX_REQUIRED.

    I then tried to remove EJB B in the A's ejbRemove() method. Same result. Now I don't understand this at all, since
    these are now 2 different transactions.

    So the pseudo code is something like this

    client method
    {
        A a = AHome.create();
        a.foo();
        a.remove();
    }


    ABean::foo()
    {
        b = BHome.create(); // b is defined as an instance attribute B (for ejbRemove())
        ...
        b.remove(); // This throws an exception
    }

    ABean::ejbRemove()
    {
        b.remove(); // This throws an exception
    }

    I'd like to know
    1. Why doesn't remove work in foo()? Where does it say in the specs that I can't remove an EJB in a transaction? 6.6.4 of EJB 1.1 talks specifically about Stateful session bean.
    2. Even if #1 is correct, the second call in ejbRemove() is another transaction. So at least the second call should
    have worked. Sections 6.5.7 and 11.6.3 state that ejbRemove run in an "unspecified transaction context".

    How do I do clean up and return the bean back to the pool if I can't remove it? I'd like to inform to the container that I
    no longer need B and would like to return it to the pool. Instead of waiting for the container to passivate it.

    Regards
    Milind
  2. I dealing with the same problem but I haven't found a solution yet. If I know one I will inform you about it.