Hi!

> Carlos Pita wrote:
>     Supose I have, for example, 2 bean-managed persistence entity bean
> instances in a pool. A client create a new entity and one of them is
> used. While it is being created, the bean instance gets a data source
> and opens a connection. 

Ok so far.

> In some way (perhaps storing it in another
> bean) the entity saves the connection. 

Nope, don't. Why would you? In any case, this will break things.

> Then the second bean instance
> in the pool is activated; before creating a new connection it checks
> to see if there is a saved connection (in the place where the other
> instance saved it). 

Beans get connections from a DataSource. Period. If you want to mess
with things, prepare to feel pain.

> The connection is already there, so the second
> bean uses it. 

==pain.

> Supose then that both instances where used in different
> transactional contexts. When the first got the connection the
> corresponding XAResource was enlisted with the first transaction. When
> the second reused the connection it was already enlisted with the
> first transaction (I can't see a place where a hook to stop/start the
> XAResource could be). 

In Connection.close. See, told ya, shouldn't have hold on to that
connection. Bad voodoo, man.

> The JTA specification says:
> 
>     "Different Java threads may be using the same connection resource
> to access the resource manager if the connection spans multiple method
> invocation [...] it's possible for different threads to be invoking
> the XAResource start and end methods [...] If the applcation server
> allows multiple threads to use a singe XAResource object and the
> associated connection to the resource manager, it is the
> responsability of the application server to ensure that there is only
> one transaction context asociated with the resource at any point of
> time"

Exactly.

>     The EJB specification says:
> 
>     "Because this resource factories allow the Container to affect
> resource management, the connections acquired through the resource
> manager connection factory are called managed resources (these
> resource factories allow the Container to implement connection pooing
> and !!!automatic enlistment of the connection with a transaction!!!)."

Indeed. Correct.

>     From this I couldn't not conclude that providing a special factory
> is the only way for a Container to asociate a XAResource with a
> transaction. But it says almost that, doesn't it?. So:

Yes, and this is what Aaron has implemented: a DataSource implementation
that does this piece of the trick.

> 1) The scenario I described above is wrong -I mean, something in it is
> not possible- (I'm new with EJB).

Yes, stick with the normal way of using connections: get it, use it,
close it.

> 2) EJB does't support "multiple threads to use a singe XAResource" so
> I should avoid the scenario.

Exactly.

> 3) The scenario is possible and EJB implementations have more tricks
> than those resource factories to reasociate (stop/start) XAResource
> with transactions.

Yes, it does start on pool.get and stop on connection.close.

>     (I could be a little off-topic because the question doesn't
> directly refer to jBoss. Sorry if this is the case: don't answer me.
> Or answer me if jBoss supports multiple threads with... :) )

No problemo. 

R U with me on the above?

/Rickard

-- 
Rickard �berg

Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com

Reply via email to