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

itwanderer 2011-03-03 04:57:28
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>
结果都一样 有的创建成功了 有的创建失败了 在线等高手指点啊

...全文
110 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wad12302 2011-03-03
  • 打赏
  • 举报
回复
<aop:pointcut id="allManagerMethod" expression="execution(* hotlong.asset.service.*.*(..))"/>

这个配置没问题,吧你上面的代码封装下

正好 eclipse开着 帮你封装下:

package hotlong.asset.dao;

/**
*
* @Description:
*
* @author weisd Email:xiyangdewuse@163.com
* @date 2011-3-3 下午11:23:03
* @version v1.0
*/
public interface TestDao {

public void saveInfo1(Object obj);
public void saveInfo2(Object obj);
public void saveInfo3(Object obj);
}


package hotlong.asset.dao.impl;

import hotlong.asset.dao.TestDao;

/**
*
* @Description:
*
* @author weisd Email:xiyangdewuse@163.com
* @date 2011-3-3 下午11:23:35
* @version v1.0
*/
public class TestDaoImpl extends HibernateDaoSupport implements TestDao {

// 我没引入jar 包
public void saveInfo1(Object obj) {
// save()//插入数据库
}

public void saveInfo2(Object obj) {
// TODO Auto-generated method stub
// save()//插入数据库
}

public void saveInfo3(Object obj) {
// TODO Auto-generated method stub
// save()//插入数据库

}

}


package hotlong.asset.servic;

/**
*
* @Description:
*
* @author weisd Email:xiyangdewuse@163.com
* @date 2011-3-3 下午11:20:35
* @version v1.0
*/
public interface TestService {

public void saveInfo(Object obj);

}


package hotlong.asset.servic.impl;

import hotlong.asset.servic.TestService;

package hotlong.asset.servic.impl;

import hotlong.asset.dao.TestDao;
import hotlong.asset.servic.TestService;

/**
*
* @Description:
*
* @author weisd Email:xiyangdewuse@163.com
* @date 2011-3-3 下午11:21:30
* @version v1.0
*/
public class TestServiceImpl implements TestService {

private TestDao testDao;

public void saveInfo(Object obj) {
// 这里才是重点 必须是所有的操作都在一个service里面
//应为你的 execution(* hotlong.asset.service.*.*(..))
// 是拦截到 service
testDao.saveInfo1(obj);
testDao.saveInfo2(obj);
testDao.saveInfo3(obj);

throw new RuntimeException("所有的sava都会回滚,记得spring 回滚要抛出运行时异常");

}

public TestDao getTestDao() {
return testDao;
}

public void setTestDao(TestDao testDao) {
this.testDao = testDao;
}

}

ojwftded 2011-03-03
  • 打赏
  • 举报
回复
zn85600301 2011-03-03
  • 打赏
  • 举报
回复
第一种
<aop:pointcut id="allManagerMethod" expression="execution(* hotlong.asset.service.*.*(..))"/>
你的事务拦截器只捕获service该层抛出的异常
你看看你是不是在DAO层已经 加了try catch 捕获过异常了

679

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧