Spring Transaction Management:
This can be done in two ways:
One is to use AOP to control transactions:
<!--configuration Transaction Manager-
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" >
<ref local= "Sessionfactory"/>
</property>
</bean>
<!--configuring transaction Features--
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "*" propagation= "REQUIRED"/>
<!--
<tx:method name= "add*" propagation= "REQUIRED"/>
<tx:method name= "del*" propagation= "REQUIRED"/>
<tx:method name= "update*" propagation= "REQUIRED"/>
<tx:method name= "deploy*" propagation= "REQUIRED"/>
<tx:method name= "submit*" propagation= "REQUIRED"/>
<tx:method name= "*" read-only= "true"/>
-
</tx:attributes>
</tx:advice>
<!--What classes of methods are configured for transaction management--
<aop:config>
<aop:pointcut id= "Allmanagermethod" expression= "Execution (* com.bjsxt.oa.managers.*.* (..))" />
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "Allmanagermethod"/>
</aop:config>
Two is to control transactions by means of a transaction interceptor:
<!--Transaction Manager for a single Hibernate sessionfactory (alternative to JTA)-- <bean id= "Mytransactionmanager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" >
<ref local= "mysessionfactory"/>
</property>
< /bean>
<!--configuration Transaction Management-
<bean id= "UserService" class= " Org.springframework.transaction.interceptor.TransactionProxyFactoryBean ">
<property name=" TransactionManager ">
<ref local=" Mytransactionmanager "/>
</property>
<property name=" Target ">
<ref local=" Logintarget "/>
</property>
<property name=" transactionattributes >
<props>
<prop key= "save*" >PROPAGATION_REQUIRED</prop>
</props>
</ Property>
</bean>
<!--Ordertarget Primary business object implementation--
<bean id= "Logintarget" class= "Com.test.spring.UserServiceImpl" >
<property name= "Userdaoif" >
<ref local= "Userdao"/>
</property>
</bean>
<!--DAO Object:hibernate implementation--
<bean id= "Userdao" class= "Com.test.hibernate.UserDAOImpl" >
<property name= "Sessionfactory" >
<ref local= "Mysessionfactory"/>
</property>
</bean>