救命啊在线等 ssh事务如何配置

itwanderer itwanderer 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public void creatework(long processorid,long resourceid,Systeminfo si, Processorinfo pif, Osinfo oif,
Networkinfo nif, Monitorinfo moif, Mouseinfo muif,
Keyboardinfo kif, Memoryinfo mmif, Assetri ast, Resources rs,
Resourcecost rsc, Resourcelocation rsl, Systeminfodomain sido,
Networkdnsinfo nkif, Date acquisitiondate, Date warrantyexpiry,
Date expirydate) {
this.getHibernateTemplate().save(si);
this.getHibernateTemplate().save(pif);
this.getHibernateTemplate().save(oif);
this.getHibernateTemplate().save(nif);
this.getHibernateTemplate().save(moif);
this.getHibernateTemplate().save(muif);
this.getHibernateTemplate().save(kif);
this.getHibernateTemplate().save(mmif);
this.getHibernateTemplate().save(rs);
}

在一个创建页面中提交后要创建好几条数据 为了保存数据完整性需要配置事务,此方法 还不能分开创建,如果一个失败要全部回滚,我已经配置了 但就是不管用 望高手指点 下面是spring的配置
第一种
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 那些类那些方法使用事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* hotlong.asset.service.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>

<!-- 事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
第二种
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="persist*">
PROPAGATION_REQUIRED,-Exception
</prop>
<prop key="remove*">
PROPAGATION_REQUIRED,-Exception
</prop>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="save">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="disPlay*">PROPAGATION_REQUIRES_NEW</prop>
<prop key="changeState*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
结果都一样 有的创建成功了 有的创建失败了 在线等高手指点啊

...全文
评论 3
收藏 已收藏
分享
返回顶部