This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes CMT and Connection Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "CMT and Connection Objects" Watch "CMT and Connection Objects" New topic
Author

CMT and Connection Objects

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
In Mikalai's notes: it's written that:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void someMethod(...) {
// obtain con1 and con2 connection objects
con1 = ...;
con2 = ...;
stmt1 = con1.createStatement();
stmt2 = con2.createStatement();

//
// Perform some updates on con1 and con2. The container
// automatically enlists con1 and con2 with the container-
// managed transaction.
//
}

As we have specified TransactionAttributeType.REQUIRED, container will start a transaction (i guess on a Connection)
Q- a) Container will start transaction on which Connection (database) Object? From where it obtains information about my database ?
In other words does container uses JTA (Distributed transaction manager layer), from where it obtains info regarding my databses,
user password, url etc..
Q- b) What does the statement means "The container automatically enlists con1 and con2 with the container-manager transaction"?
Deepika Joshi
Ranch Hand

Joined: Feb 24, 2009
Posts: 268
JTA is (default) transaction manager for EJB3,

From where it obtains information about my database? from where it (JTA) obtains info regarding my databses, user password, url etc..

if you are reading EJB3 In Action, then check out "Listing 11.6 An example persistence.xml, page 411";
where user provides, transaction-type = "JTA", provider=toplink & jta-data-source=dataSourceName
In your application server you provide information for dataSource - i.e. dsName, user, password
check out page 415 of EJB3IA for glassfish App. server DataSource settings....





Container will start transaction on which Connection (database) Object?

if you are ware of ACID properties of transaction which means (in short) all done (commit everything) or nothing (rollback everything),
so all the resources (connections) enclosed in boundary of transaction will participate in transaction.

What does the statement means "The container automatically enlists con1 and con2 with the container-manager transaction"?

container-manager transaction > user is not writing any transaction mgmt code, user is just asking for transaction service
container is initiating transaction service & con1 & con2 are participating...

hope it may be helpful...
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Thanks Deepika for the answers...
i was a bit confused about local transaction and distributed transactions...
I found the following good links which clarifies these:
1) http://archive.devx.com/java/free/articles/dd_jta/jta-1.asp
2) http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/tjvcmtrl.htm

Crux is:
For local transaction (JDBC) - We first obtain Connection Object and use it's API to control transaction...
For a global distributed transaction(JTA) - We start a transaction and whatever operations we perform on any connection object will be the part of this transaction..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: CMT and Connection Objects
 
Similar Threads
JDBC Transactions across multiple databases
junk characters for byte charset
resultset problem
CMT and Connection Objects
Is this possible