SpringMvc Jpa mysql开发项目,事务失效,现象:Controller增加和修

收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 SpringMvc Jpa mysql开发项目,事务失效,现象:Controller增加和修改无效,但单元测试可以,不知道什么原因,代码如下:
各位高手帮忙解决一下啊,谢谢了。


实体类:
@Entity
public class Customer implements Serializable{
private static final long serialVersionUID = -803075682525328610L;
private Integer customerId;
private String loginName;
private String password="123456";
private String nickName;
private String email;
private String cellphone;
@Id @GeneratedValue
public Integer getCustomerId() {
return customerId;
}
}
DAO:
public interface DAO {
public void save(Object entity);
}
DAO抽象类:
@Transactional
public abstract class DaoSupport implements DAO {
protected Class entityClass = GenericsUtils.getSuperClassGenricType(this.getClass());
@PersistenceContext protected EntityManager em;
public void save(Object entity) {
em.persist(entity);
}

}

Service层:
public interface CustomerService extends DAO{
}

@Service
@Transactional
public class CustomerServiceBean extends DaoSupport implements CustomerService {
}


Controller层:
@Controller
public class ModiPersonDataController {
@Resource CustomerService customerService;

@RequestMapping("/modiPersonDataUI.do")
public String jumpToModiUI() {
return "modiPersonData";
}
/**
* 修改个人资料和密码
*/
@RequestMapping("/modiPersonData.do")
public void modiPersonData(CustomerForm customerForm){
Customer customer = new Customer();
customer.setLoginName(customerForm.getLoginName());
customer.setPassword(customerForm.getPassword());
customer.setNickName(customerForm.getNickName());
customer.setCellphone(customerForm.getCellphone());
customer.setEmail(customerForm.getEmail());
customerService.save(customer);
}
}

webform层:
public class CustomerForm implements Serializable{
private static final long serialVersionUID = -4425312158083346598L;
private Integer customerId;
private String loginName;
private String password;
private String nickName;
private String cellphone;
private String email;
public String getLoginName() {
return loginName;
}
。。。
}

persistence.xml 配置如下:


xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

org.hibernate.ejb.HibernatePersistence










beans.xml配置如下:























jdbc.properties)(略)

spring mvc 配置如下:



p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>

web.xml 配置如下:
Spring Annotation MVC Sample


contextConfigLocation
classpath:beans.xml




org.springframework.web.context.ContextLoaderListener



annomvc
org.springframework.web.servlet.DispatcherServlet

2


annomvc
*.do


[该贴被zhaome于2010-03-16 16:36修改过]

顶一下,在线等待您的回复。
第一次在这儿发帖,居然没人帮忙,真冷清啊。
贴一大堆代码上来,谁有时间帮你检查代码啊,自己搞断点调试吧,在事务失败发生之前看断点研究吧。

代码调试应该是程序员基本技能。

如果有设计问题,可贴一些图上来表达,不好意思,帮不了你。

原因是:事务没有起动
谢谢,我试试。