收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 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修改过]