Win a copy of Rust Web Development this week in the Other Languages forum!

T Stevens

Greenhorn
+ Follow
since Jan 23, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by T Stevens

Thanks for your reply. I'm quite happy with the basic concepts, the bit that is confusing me is that it is possible to open and close multiple JDBC connections - I'd like to know how the transactions are managed at the database level.
Example:


In this example, businessMethodA calls businessMethodB and businessMethodC, both of which request and use a JDBC connection. My question is, how is this managed as a single database transaction, because to the developer it appears not to be.
I've been trying to get my head around CMT and been struggling to work out how the Container does the management.

Assume that I'm doing simple non-XA single-datasource database access in EJB 3.0 and configured the Stateless Session Bean using @TransactionManagement(TransactionManagementType.CONTAINER)

So, when I call a method (methodA), I decide that I need a database connection. So, I use a JNDI lookup to obtain the datasource, get a new connection and do some SQL. The spec says that I mustn't do a commit on the connection, so I finish the code with a connection.close().


My question is, how does the connection know to participate in the transaction that is defined at the SSB level. Presumably, methodA can call methodB which could call similar code, again connecting to the database and doing some more SQL. How does the container co-ordinate this given that I have closed the connection myself?