顺便补充一句:事务管理配置起来会有点复杂,特别对于entity Bean,2.0支持nest Transcation和多种transction type。这方面要肯多实践,多专研才有收获,听别人讲怎么也不会完全明白的。 给个配置的大概样子: <assembly-descriptor> <!-- This demonstrates setting a transaction attribute on every method on the bean class. --> <container-transaction> <method> <ejb-name>Employee</ejb-name> <method-name>*</method-name> </method> <!-- Transaction attribute. Can be "NotSupported", "Supports", "Required", "RequiresNew", "Mandatory", or "Never". --> <trans-attribute>Required</trans-attribute> </container-transaction> <!-- You can also set transaction attributes on individual methods. --> <container-transaction> <method> <ejb-name>Employee</ejb-name> <method-name>setName</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> <!-- You can even set different transaction attributes on methods with the same name that take different parameters. --> <container-transaction> <method> <ejb-name>Employee</ejb-name> <method-name>setName</method-name> <method-param>String</method-param> </method> <trans-attribute>Required</trans-attribute> </container-transaction> </assembly-descriptor>
这个我知道,我的意思是: begintran save 1 //ok 主表 save 2 //errro rollback 明细 save 3 //明细 commit tran这种情况下的,该如何使用bean(CMP2.0)来实现?
给个配置的大概样子:
<assembly-descriptor>
<!--
This demonstrates setting a transaction attribute
on every method on the bean class.
-->
<container-transaction>
<method>
<ejb-name>Employee</ejb-name>
<method-name>*</method-name>
</method>
<!--
Transaction attribute. Can be "NotSupported",
"Supports", "Required", "RequiresNew",
"Mandatory", or "Never".
-->
<trans-attribute>Required</trans-attribute>
</container-transaction>
<!--
You can also set transaction attributes on individual methods.
-->
<container-transaction>
<method>
<ejb-name>Employee</ejb-name>
<method-name>setName</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<!--
You can even set different transaction attributes on
methods with the same name that take different parameters.
-->
<container-transaction>
<method>
<ejb-name>Employee</ejb-name>
<method-name>setName</method-name>
<method-param>String</method-param>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
begintran
save 1 //ok 主表
save 2 //errro rollback 明细
save 3 //明细
commit tran这种情况下的,该如何使用bean(CMP2.0)来实现?
想用bmt应该在session bean里面用