spring和hibernate我不是很明白,但是用过。
第一:你既然要用编程式事务,那和spring有什么关系,直接Transaction begin,comimt就OK了。
第二:你要是用的声明式事务,那就不要在程序里Transaction!而是在applicationContext.xml配
//你所的DAO必须注入同一个sessionFactory
//声明事务管理器
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
//声明事务
<bean id="业务对象代理"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
<property name="target" ref="业务对象" />
<property name="transactionAttributes">
<props>
<prop key="添加要声明事务的方法">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

解决方案 »

  1.   

            <!--获取hibernate工厂-->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation"
    value="classpath:hibernate.cfg.xml">
    </property>
    </bean> <!-- 事务处理 -->
    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
    <tx:method name="get*" propagation="SUPPORTS"
    read-only="true" />
    <tx:method name="load*" propagation="SUPPORTS"
    read-only="true" />
    <tx:method name="find*" propagation="SUPPORTS"
    read-only="true" />
    <tx:method name="search*" propagation="SUPPORTS"
    read-only="true" />
    <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="bizMethods"
    expression="execution(* .*.*(..))" /><!--此处写上你要调用数据操作的BO层包(com.bo)-->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
    </aop:config>
      

  2.   

    使用
    <bean id="DAO" class="com.dao.ComDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="combo" class="com.bo.ComBo"></bean>