It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Difference between connection.commit and usertransaction.commit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Difference between connection.commit and usertransaction.commit" Watch "Difference between connection.commit and usertransaction.commit" New topic
Author

Difference between connection.commit and usertransaction.commit

Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
Hi
If I get a connection from a datasource (conn pool) then what is the difference between
(1)commit()/rollback() on the connection direction
Versus
(2) commit() /rollback() on the user transaction
Thanks
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

One's a database operation, the other a user process.


[OCA 8 Book] [Blog]
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
connect.commit() is database process and usertxn.commit() is user process right? But what does this mean to the developer or to the runtime?
Given that there are two choices of doing things, which one should I pick and why?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32508
    
214

Babji,
They mean different things. Suppose a transaction contains multiple database connections. Committing the user transaction would commit all of them. Whereas committing the connection would only commit one.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
Thanks Jeanne,
If a transaction contains multiple database connections, then its a distributed /XA transaction right?
Lets keep it as multiple i/o operations with the same database. which can be commit/rollback either using a single usertransaction or connection.

When we use UserTransaction the transaction manager/service uses a default timeout (which if we want, we can overwrite using setTransactionTimeout method)
But if I use a connection directly (for a set of lengthy database processes) then I donot need to worry about the timeout. is this right?
If so is this the only difference?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32508
    
214

Babji,
Connections have inactivity timeouts. I don't recall whether they have timeouts if the connection is in use the whole time.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Difference between connection.commit and usertransaction.commit
 
It's not a secret anymore!