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类型?