81,094
社区成员
发帖
与我相关
我的任务
分享
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置那些类的方法进行事务管理,当前com.ilb.dao包中的子包、类中所有方法需要,还需要参考tx:advice的设置 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution (* com.cloudsoar3c.biz.impl.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
public void add(Object ogj) throws Exception{
super.getHibernateTemplate().getSessionFactory().getCurrentSession().save(ogj);
}
public TOrder addNewOrder(Integer buyCount, TClient client)throws Exception{
TServerHostLicense serverHostLicense = new TServerHostLicense();
serverHostLicense.setHostId(System.currentTimeMillis()+"");
serverHostLicense.setAddTime(new Date());
serverHostLicense.setHostName("测试主机名");
serverHostLicense.setLicenseFile("licenseFile........");
serverHostLicense.setStatus(-1);
serverHostLicense.setSupportClientCount(buyCount);
serverHostLicense.setTClient(client);
//添加主机服务器信息
//boolean addResult = this.serverHostLicenseDao.add(serverHostLicense);
this.serverHostLicenseDao.add(serverHostLicense);
TLicensePrice licensePrice = getPriceByBuyCount(buyCount);//获取单价
TOrder order = new TOrder();
//生成订单ID
String orderId = this.utilBiz.getUUID(Attribute.UUID_ORDER);
order.setOrderId("1362726845687907");//此处ID故意重复,让其出错
order.setBuyCount(buyCount);
order.setOrderTime(new Date());
order.setPreferentialPrice(0);//默认优惠价格为0
order.setPrice(licensePrice.getPrice());
order.setStatus(Attribute.ORDER_STATE_DFK);//初始化状态为待付款状态
order.setTClient(client);
order.setTServerHostLicense(serverHostLicense);
order.setTotalPrice((Integer.parseInt(licensePrice.getPrice())*buyCount+""));
this.orderDao.addOrder(order);//添加新增订单到数据库中
return order;
try {
order = this.orderBiz.addNewOrder(buyCount, client);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public TOrder addNewOrder(Integer buyCount, TClient client){
TServerHostLicense serverHostLicense = new TServerHostLicense();
serverHostLicense.setHostId(System.currentTimeMillis()+"");
serverHostLicense.setAddTime(new Date());
serverHostLicense.setHostName("测试主机名");
serverHostLicense.setLicenseFile("licenseFile........");
serverHostLicense.setStatus(-1);
serverHostLicense.setSupportClientCount(buyCount);
serverHostLicense.setTClient(client);
//添加主机服务器信息
//boolean addResult = this.serverHostLicenseDao.add(serverHostLicense);
this.serverHostLicenseDao.add(serverHostLicense);
//TLicensePrice licensePrice = getPriceByBuyCount(buyCount);//获取单价
TOrder order = new TOrder();
//生成订单ID
//String orderId = this.utilBiz.getUUID(Attribute.UUID_ORDER);
order.setOrderId("1362726845687907");//此处ID故意重复,让其出错
order.setBuyCount(buyCount);
order.setOrderTime(new Date());
order.setPreferentialPrice(0);//默认优惠价格为0
//order.setPrice(licensePrice.getPrice());
order.setPrice("111");
order.setStatus(Attribute.ORDER_STATE_DFK);//初始化状态为待付款状态
order.setTClient(client);
order.setTServerHostLicense(serverHostLicense);
//order.setTotalPrice((Integer.parseInt(licensePrice.getPrice())*buyCount+""));
order.setTotalPrice("2222");
this.orderDao.addOrder(order);//添加新增订单到数据库中
if(1==1){
throw new RuntimeException("");
}
return order;
}
<aop:pointcut id="allManagerMethod" expression="execution (* com.cloudsoar3c.biz.*.*(..))"/>
public void add(Object ogj) throws Exception{
super.getHibernateTemplate().getSessionFactory().getCurrentSession().save(ogj);
}
try {
order = this.orderBiz.addNewOrder(buyCount, client);
} catch (Exception e) {
// TODO Auto-generated catch block
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
}
try {
order = this.orderBiz.addNewOrder(buyCount, client);
} catch (Exception e) {
// TODO Auto-generated catch block
//这里怎么没有实物回滚语句呢?XXX.rollback();
e.printStackTrace();
}