g*g
2 楼
Of course you do it in service. So you make decision whether to rollback
with certain exception, whether to combine multiple writes into one
transaction etc. How else can you do it when you operate multiple DAOs?
Keep dao simple and dumb. The way I like to think what DAO should be is:
If you have to change to another DB, with a very different implementation (
JDBC, iBatis you name it). Can you not alter your service, and still
minimize the code you have to write on new DAO.
【在 z*******3 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: service还是dao/repository?
with certain exception, whether to combine multiple writes into one
transaction etc. How else can you do it when you operate multiple DAOs?
Keep dao simple and dumb. The way I like to think what DAO should be is:
If you have to change to another DB, with a very different implementation (
JDBC, iBatis you name it). Can you not alter your service, and still
minimize the code you have to write on new DAO.
【在 z*******3 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: service还是dao/repository?
t*e
3 楼
应该问从哪一层开始transaction. 从web就可以开始了。
z*3
4 楼
我也是觉得在service做比较合理
但是在service做,spring用aop来作,ejb容器用显式的transaction标记来做
appengine的objectify就没有办法了,除非加上guice的aop
那样就大了,就慢了,所以我现在只能做在dao里面
从web就开始做,有点太过于早了点
毕竟action跟service很可能是在不同物理机器上的
这样跨机器搞transaction是忌讳,还是不要了
但是在service做,spring用aop来作,ejb容器用显式的transaction标记来做
appengine的objectify就没有办法了,除非加上guice的aop
那样就大了,就慢了,所以我现在只能做在dao里面
从web就开始做,有点太过于早了点
毕竟action跟service很可能是在不同物理机器上的
这样跨机器搞transaction是忌讳,还是不要了
w*z
6 楼
from my previous job, we start transaction in service layer.
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Of course you do it in service. So you make decision whether to rollback
: with certain exception, whether to combine multiple writes into one
: transaction etc. How else can you do it when you operate multiple DAOs?
: Keep dao simple and dumb. The way I like to think what DAO should be is:
: If you have to change to another DB, with a very different implementation (
: JDBC, iBatis you name it). Can you not alter your service, and still
: minimize the code you have to write on new DAO.
【在 g*****g 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Of course you do it in service. So you make decision whether to rollback
: with certain exception, whether to combine multiple writes into one
: transaction etc. How else can you do it when you operate multiple DAOs?
: Keep dao simple and dumb. The way I like to think what DAO should be is:
: If you have to change to another DB, with a very different implementation (
: JDBC, iBatis you name it). Can you not alter your service, and still
: minimize the code you have to write on new DAO.
s*e
7 楼
感觉db transparent对绝大多数公司来说只有理论上的好处,好多年前,我们的还把这
个作为要求之一,现在发现,在一个大公司,换DB的可能性太小了,与其在上面投入精
力,不如根本不考虑,等到真正换的时候再说。
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Of course you do it in service. So you make decision whether to rollback
: with certain exception, whether to combine multiple writes into one
: transaction etc. How else can you do it when you operate multiple DAOs?
: Keep dao simple and dumb. The way I like to think what DAO should be is:
: If you have to change to another DB, with a very different implementation (
: JDBC, iBatis you name it). Can you not alter your service, and still
: minimize the code you have to write on new DAO.
个作为要求之一,现在发现,在一个大公司,换DB的可能性太小了,与其在上面投入精
力,不如根本不考虑,等到真正换的时候再说。
【在 g*****g 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Of course you do it in service. So you make decision whether to rollback
: with certain exception, whether to combine multiple writes into one
: transaction etc. How else can you do it when you operate multiple DAOs?
: Keep dao simple and dumb. The way I like to think what DAO should be is:
: If you have to change to another DB, with a very different implementation (
: JDBC, iBatis you name it). Can you not alter your service, and still
: minimize the code you have to write on new DAO.
g*g
12 楼
o*i
13 楼
想体验一把hibernate今天去和头说能不能在我负责的project里用hibernate结果被秒据
了。。。
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 看你项目有多小了,写完就可以扔掉是不需要。业界的框架和工具都是根据这些分层的
: 理念
: 来设计的,为的是好的可扩展性和可维护性。即便显得繁琐,也可以使日后的维护变得
: 简单。
: 以spring+hibernate为代表的中后层,现在并没有明显的冗余代码。事实上一个
: annotation就可以标明transaction,不能再简单了。这要比写JDBC容易多了。
: 如果项目非常简单,可以考虑的是用Spring Roo之类的工具直接把大部分代码生成了。
了。。。
【在 g*****g 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 看你项目有多小了,写完就可以扔掉是不需要。业界的框架和工具都是根据这些分层的
: 理念
: 来设计的,为的是好的可扩展性和可维护性。即便显得繁琐,也可以使日后的维护变得
: 简单。
: 以spring+hibernate为代表的中后层,现在并没有明显的冗余代码。事实上一个
: annotation就可以标明transaction,不能再简单了。这要比写JDBC容易多了。
: 如果项目非常简单,可以考虑的是用Spring Roo之类的工具直接把大部分代码生成了。
相关阅读
Re: component之间怎样送消息?Re: ABout BrowserRe: 如何从Datagram Socket里读object折腾了一天,实在是绝望了,请教请教Re: 这功能咋做水平比较高?Re: 这个错误是程序的原因还是JAVA的原因火车旅行家在中文WINDOWS下无法运行的大问题已被解决Re: Java Mail APIRe: 如何在运行Java程序时让dos窗口不出现呢?[转载] Java runs faster on MSIE 4.02 than NS 4.5Re: when do I need to recompileTest your PC speedRe: Do anyone know a good websit containing the source code of JavaRe: abstract classes GRAPHICSRe: Code Naming StyleRe: native thread 和green threadRe: SWING中如何实现TEXTLISTENERRe: JTextArea的内容不滚动Stack Frame of your JVM implementationRe: 如何读取serial port in Java