Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Architecture & Framework  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 关于事务的问题
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2005-05-04 17:20 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在j2ee体系里面,这些东西可以管理事务:
1. EJB
2. Spring
3. ibatis, hibernate, jdo, top link这些persistance layer我想都有自己的对事务的管理
4. JTA

其中,EJB跟Spring可以支持declarative的事务
nested transaction我只知道EJB3好像是打算引入了 Spring我不知道
------------------------------------------
不知道以上说的对不对
------------------------------------------
如果对的话,问题如下:
------------------------------------------
我比较弱智的 非EJB项目就赤膊上阵用persistant layer的了 这样做感觉不太好也。。。
大家在自己的项目里面怎么管理事务的?难道都用上Spring了?



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:关于事务的问题 [Re:jigsaw]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2005-05-04 17:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
或者说 大家喜欢到jndi里面拿usertransaction来用?


No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:关于事务的问题 [Re:jigsaw]
emarket

亢龙有诲

CJSDN高级会员


发贴: 460
积分: 82
于 2005-05-04 17:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果是 distribute 的 ,例如,有多个数据库, 或者有EIS, 就要用到JTA,

如果是单一数据库,最简单的 connection.comit() 就可以了。

BTW: 在J2EE里面 唯一可以处理transaction的实 JTA.



个人Blog http://agilespeaking.blogspot.com/

作者 Re:关于事务的问题 [Re:jigsaw]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2005-05-04 17:36 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我知道 ejb也是靠jta的 但是包装得已经很好了 根本不用管UserTransaction
难道。。。就用conn.commit啊。。。
那就是说 直接用那些persistant工具的咯



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:关于事务的问题 [Re:jigsaw]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-05-04 22:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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
作者 Re:关于事务的问题 [Re:jigsaw]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2005-05-05 00:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我觉得conn.commit以及类似的表达方式,比如:

xxx.startTransaction();
// bizness method here
xxx.commitTransaction();

最烦的地方就是把事务的边界写死在程序里面了。

这种写死的后果就是这个service方法不能判断当前的context。
我希望的是象CMT那样,定义几个require/requirenew等等等等,
当service跑的时候,可以自动根据当前context---也就是当前是否已经start勒一个transaction---来决定是否开始一个新的transaction。
当然,这个要求CMT已经达到了,spring也作得很好了。
但是两者之间呢?spring加入事务管理之前,且没有上EJB的项目里面,就只有写死在程序里面啦? ---- 我自己是这样的,感觉很烦,所以想知道别人有啥好办法。看来。。。也都一样无奈咯?



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:关于事务的问题 [Re:jigsaw]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2005-05-06 11:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I am not aware of any better solutions. Other folks?


"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
作者 Re:关于事务的问题 [Re:jigsaw]
haibo



CJSDN高级会员


发贴: 322
积分: 71
于 2005-05-07 20:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看了半天,没弄明白你想要啥样的事务管理,俺用的hiabernate in action 里说到的long Session,从dao诞生时开始beingTransaction ,到jsp页 面生成后在filter里commitTransaction(),中间过程牵涉到的事务不知道是不是你说的nested transaction,他们都是从Thread Local 域里定义的同一个session开始的transaction,所以不管中间调用了多少次,begin Transaction,只要前面已经启动了一个transaction了,他们都还是在一个transaction中,直到最后filter完成后commit.
这样保证在一个线程里只有一个transaction.




作者 Re:关于事务的问题 [Re:jigsaw]
wes109

以梦为马

CJSDN高级会员


发贴: 857
积分: 60
于 2005-05-08 11:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
楼上,你那个too simple啦,哈哈

看一下cmt定义的各种事务类型就知道了
你那个也就是算个Required
《Mastering ejb》里面有很详细的介绍





flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923