As described in section 5.5.4 of Connector Architecture 1.0 spec, JBoss calls getConnection multiple times on a ManagedConnection instance. It leads to existing of several connection handles to a single ManagedConnection, but only one of them is active.
How the container switches the active connection handle?
Container seem not to invoke assosiateConnection method on ManagedConnection, as described in section 9.11.
The scenario of my problem:
The first EJB requests a connection handle. JBoss invokes resource adapter to create a new ManagedConnection.
The first EJB invokes the second EJB. The second EJB requests a connection handle. JBoss invokes getConnection on the same ManagedConnection without even invoking matchManagedConnection. The second EJB uses this handle and closes it.
The first EJB tries to use the connection it obtained earlier and fails because this connection is not active.
Are you using Container-managed connections? You need to set your -ds.xml to use ByContainer or whatever the parameter is.