riko1986 2009-03-02 22:32
浏览 256
已采纳

spring事务不回滚

struts+hibernate+spring架构,数据库为mysql,表类型MyISAM
spring配置如下:
[code="java"]
class="org.springframework.orm.hibernate3.HibernateTransactionManager">



<bean  id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="save*">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>

<bean id="productServiceProxy" parent="txProxyTemplate">
    <property name="target">
        <ref bean="productService"/>
    </property>
</bean>

<bean name="/admin/test"
    class="com.chaoshang.struts.action.TestAction">
    <property name="productService">
        <ref local="productServiceProxy" />
    </property>
</bean>

<bean id="productService"
    class="com.chaoshang.service.ProductService">
    <property name="productDAO">
        <ref bean="ProductDAO" />
    </property>
</bean>

ProductService类:
public class ProductService implements IProductService{
private ProductDAO productDAO;
public void save(Product p){
Product p1 = new Product();
Product p2 = new Product();
p1.setName("p1");
p2.setName("p1");
productDAO.save(p1);
productDAO.save(p2);
//product的name有唯一约束,p2将会插入失败,故回滚,p1也插入失败!但p1插入成功了

}
public ProductDAO getProductDAO() {
return productDAO;
}
public void setProductDAO(ProductDAO productDAO) {
this.productDAO = productDAO;
}
}

IProductService接口:
public interface IProductService {
public abstract void save(Product p);
}

TestAction类:
public class SaveOrUpdateProductSubmitAction extends Action{

private IProductService productService;

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
    productService.save(product);
    return mapping.findForward("success");
}
public IProductService getProductService() {
    return productService;
}
public void setProductService(IProductService productService) {
    this.productService = productService;
}

}

[/code]
如果配置为:PROPAGATION_REQUIRED,readOnly会报“xxx read-only xxx”异常,证明spring拦截了该方法了,但怎么事务不回滚呢?
[b]问题补充:[/b]
创建表:
create table A(
id int
)type=InnoDB;
可是查看一下,表是MyISAM的,是否我的版本不支持InnoDB类型?

  • 写回答

5条回答 默认 最新

  • zhoupjam 2009-03-10 12:40
    关注

    你的版本支持InnoDB类型,是不是用了绿色版的缘故,我之前也遇到这个问题~改装正式版

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证