解决方案 »
- struts 2 No result defined 的奇怪问题
- 一道web.xml配置文件的笔试题
- 超难问题,关于html中输入的问题(能解决的绝对是高手~)
- 关于一个登录的小效果,是怎么实现的??
- jsp 如何设置相册封面
- axis1.4 webserice报 faultCode{http://schemas.xmlsoap.org/soap/envelope/}: Server.
- 关于用lucene不能删除索引的问题?谢谢!
- 用tomcat发布的jsp信息系统,网络堵塞如何解决
- ASP,JSP 的WEB开发,你选择谁?
- 请问:如何读取一条纪录的所有值?
- 网站的内容和评论分页问题
- 【求推荐】最好用的 web应用 java开发平台? 支持可视化的?【不考虑用微软的产品】
try {
order = this.orderBiz.addNewOrder(buyCount, client);
} catch (Exception e) {
// TODO Auto-generated catch block
//这里怎么没有实物回滚语句呢?XXX.rollback();
e.printStackTrace();
}
try {
order = this.orderBiz.addNewOrder(buyCount, client);
} catch (Exception e) {
// TODO Auto-generated catch block
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
}
public void add(Object ogj) throws Exception{
super.getHibernateTemplate().getSessionFactory().getCurrentSession().save(ogj);
}
试试改成这样行不行.
expression="execution (* com.cloudsoar3c.biz.*.*(..))"/>
第一个*代表的是返回值;第二个*表示的是biz下面的子包;第三个*表示的是方法名称;(..)表示的是方法参数.
试试看!!
hibernate配置文件里加上<property name="connection.autocommit">false</property>
<aop:pointcut id="allManagerMethod" expression="execution (* com.cloudsoar3c.biz.*.*(..))"/>
数据库用的mysql,刚才使用命令show variables like 'table_type';查看表类型是:MyISAM
然后我添加了<property name="connection.autocommit">false</property>问题仍然存在
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;
}
下面的代码片段说明了怎么给应用程序指定的checked异常回滚操作
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" rollback-for="NoProductInStockException"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
同样,可以指定某种异常不用回滚
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="updateStock" no-rollback-for="InstrumentNotFoundException"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置通知 -->
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- 配置通知器 -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.svse.service.*Service.*(..))"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" rollback-for="java.lang.Exception"/>
<tx:method name="doGet*" read-only="true"/>
</tx:attributes>
</tx:advice>
如果你切入点没配错的话,照理说dao,service一直上抛应该是可以回滚的...我也不懂,在学..