資源描述:
《解惑 spring 嵌套事務(wù)與ejb事務(wù)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、解惑spring嵌套事務(wù)/***@author王政*@date2006-11-24*@note轉(zhuǎn)載請注明出處*/在所有使用spring的應(yīng)用中,聲明式事務(wù)管理可能是使用率最高的功能了,但是,從我觀察到的情況看,絕大多數(shù)人并不能深刻理解事務(wù)聲明中不同事務(wù)傳播屬性配置的的含義,讓我們來看一下TransactionDefinition接口中的定義代碼/***Supportacurrenttransaction,createanewoneifnoneexists.*AnalogoustoEJBtransactionattributeofthesamename.*
Thisistypically
2、thedefaultsettingofatransactiondefinition.*/intPROPAGATION_REQUIRED=0;/***Supportacurrenttransaction,executenon-transactionallyifnoneexists.*AnalogoustoEJBtransactionattributeofthesamename.*
Note:Fortransactionmanagerswithtransactionsynchronization,*PROPAGATION_SUPPORTSisslightlydifferentfromnot
3、ransactionatall,*asitdefinesatransactionscoppthatsynchronizationwillapplyfor.*Asaconsequence,thesameresources(JDBCConnection,HibernateSession,etc)*willbesharedfortheentirespecifiedscope.Notethatthisdependson*theactualsynchronizationconfigurationofthetransactionmanager.*@seeorg.springframework.tran
4、saction.support.AbstractPlatformTransactionManager#setTransactionSynchronization*/intPROPAGATION_SUPPORTS=1;/***Supportacurrenttransaction,throwanexceptionifnoneexists.*AnalogoustoEJBtransactionattributeofthesamename.*/intPROPAGATION_MANDATORY=2;/***Createanewtransaction,suspendthecurrenttransacti
5、onifoneexists.*AnalogoustoEJBtransactionattributeofthesamename.*
Note:Actualtransactionsuspensionwillnotworkonout-of-the-box*onalltransactionmanagers.ThisinparticularappliestoJtaTransactionManager,*whichrequiresthejavax.transaction.TransactionManager
tobe*madeavailableittoit(whichiss
6、erver-specificinstandardJ2EE).*@seeorg.springframework.transaction.jta.JtaTransactionManager#setTransactionManager*/intPROPAGATION_REQUIRES_NEW=3;/***Executenon-transactionally,suspendthecurrenttransactionifoneexists.*AnalogoustoEJBtransactionattributeofthesamename.*
Note:Actualtransactionsuspen
7、sionwillnotworkonout-of-the-box*onalltransactionmanagers.ThisinparticularappliestoJtaTransactionManager,*whichrequiresthejavax.transaction.TransactionManager
tobe*madeavailableittoit(whichisserver-spe