floater
Java Jedi
总版主
发贴: 3233
积分: 421
|
于 2005-05-04 22:13
1. yes, for local transactions, conn.commit() is enough. That's why I said in another post that local/nondistributed transactions are fine. Also, in here you really don't care about declaring it or hardcoding it. It's local after all. However, the problem is when you run across different DAOs, the connection we get from DataSource may not be the same one at all, so literally, the connection.commit() is not quite working. So either work at the connection level or use Spring. The former is ugly, so Spring is very nice to resolve this. Another issue is sometimes when we turn off the autocommit(in order to comit by ourselves), we forget to commit in some if block. This will cause the leak and data loss. This is very hard to troubleshoot, because it happens not quite often(I had two cases where this happened once a month) because only in certain cases you hit that if block and you don't know where it is. So use a mature solution. 2. Nested transaction, I think, is supported at least in Spring 1.1.5 version, or maybe earlier. There had been talks about that in the forum for some time. 3. JTA is for distributed transactions, it needs suitable db drivers in order to make it work. If there are more than one db, or jms, jca are involved, then you have to use JTA, it's just a 2 phase commitment. But there is considerable overhead for JTA, comparing to local transactions. Though I don't work on all of jdo, hibernate, ibatis, toplink, I think their transactions are local only. This is based on the fact that it's not trivial to implement a 2 phase commitment and it's after all a seperate issue.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler, Refactoring - Improving the Design of Existing Code
|