• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

CMT and Connection Objects

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"?
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
I think she's lovely. It's this tiny ad that called her crazy:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic