JAVA.......hibernate修改数据, 更新不了。(SSH.使用的spring整合里面的.hibernateTemplate)
映射文件:
<property name="connection.autocommit">true</property>设置了自动提交事务
Dao层:
public boolean updatePassword(String username,String password, String repassword) {
// TODO Auto-generated method stub
String hql="from Usersinfo where username =?";
boolean validate= this.findPassword(username, password);
System.out.println(validate);
if(validate)
{
List<Usersinfo> list=this.hibernateTemplate.find(hql,username);
Usersinfo usersinfo=list.get(0);
System.out.println(usersinfo.getPassword());
usersinfo.setPassword(repassword);
System.out.println(usersinfo.getPassword());
this.hibernateTemplate.saveOrUpdate(usersinfo);
return true;
}
else{
return false;
}
}
Struts..action
:
public ActionForward updatePassword(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
DynaActionForm userForm = (DynaActionForm) form;
String username = userForm.getString("username");
String password = userForm.getString("password");
String repassword = userForm.getString("repassword");
boolean flag=userService.updatePassword(username, password, repassword);
if(flag)
{
request.setAttribute("res", "success");
return mapping.findForward("updateSuc");
}
else{
request.setAttribute("res", "error");
return mapping.findForward("updateSuc");
}
}
为什么更新不了数据呢???
映射文件:
<property name="connection.autocommit">true</property>设置了自动提交事务
Dao层:
public boolean updatePassword(String username,String password, String repassword) {
// TODO Auto-generated method stub
String hql="from Usersinfo where username =?";
boolean validate= this.findPassword(username, password);
System.out.println(validate);
if(validate)
{
List<Usersinfo> list=this.hibernateTemplate.find(hql,username);
Usersinfo usersinfo=list.get(0);
System.out.println(usersinfo.getPassword());
usersinfo.setPassword(repassword);
System.out.println(usersinfo.getPassword());
this.hibernateTemplate.saveOrUpdate(usersinfo);
return true;
}
else{
return false;
}
}
Struts..action
:
public ActionForward updatePassword(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
DynaActionForm userForm = (DynaActionForm) form;
String username = userForm.getString("username");
String password = userForm.getString("password");
String repassword = userForm.getString("repassword");
boolean flag=userService.updatePassword(username, password, repassword);
if(flag)
{
request.setAttribute("res", "success");
return mapping.findForward("updateSuc");
}
else{
request.setAttribute("res", "error");
return mapping.findForward("updateSuc");
}
}
为什么更新不了数据呢???
hibernateTemplate在spring中配了吗
把配置文件和HibernateDao的代码贴出来看看
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- Dao层注入 -->
<bean id="userDao" class="com.scjiexi.dao.UserDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- Service层注入 -->
<bean id="userService" class="com.scjiexi.service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
<!-- Action注入 -->
<bean name="/user" class="com.scjiexi.struts.action.UserAction">
<property name="userService" ref="userService"></property>
</bean>
</beans>