以下是DAO里面的方法
public boolean updateUser(Users users) {
try{
this.getHibernateTemplate().update(users);
}catch(Exception e){
e.printStackTrace();
}
return true;
}
没有抛出异常。加入内存刷新.getHibernateTemplate().update 或加入手动提交this.getSession().beginTransaction().commit();均可实现写入数据库
hibernate是交给spring管理的,applicationContext.xml文件如下:
public boolean updateUser(Users users) {
try{
this.getHibernateTemplate().update(users);
}catch(Exception e){
e.printStackTrace();
}
return true;
}
没有抛出异常。加入内存刷新.getHibernateTemplate().update 或加入手动提交this.getSession().beginTransaction().commit();均可实现写入数据库
hibernate是交给spring管理的,applicationContext.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/cmms?useUnicode=true&characterEncoding=utf-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!-- 配置Hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/cmms/bean/Users.hbm.xml</value>
<value>com/cmms/bean/Qsb.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- 配置事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 定义DAO -->
<bean id="userDAO" class="com.cmms.dao.UsersDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="qsbDAO" class="com.cmms.dao.QsbDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 定义DAO代理 -->
<bean id="UserDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="QsbDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="qsbDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- spring整合Struts2配置 -->
<bean id="loginAction" class="com.cmms.action.LoginAction">
<property name="dao"><!-- 依赖注入的dao的对象名称 -->
<ref local="userDAO" /><!-- 调用bean的id为users的dao层组建 -->
</property>
</bean>
<bean id="usersmanagementAction" class="com.cmms.action.UsersManagementAction">
<property name="dao">
<ref local="userDAO" />
</property>
</bean>
<bean id="openissureactionplanaction" class="com.cmms.action.OpenIssureActionPlanAction">
<property name="dao">
<ref local="qsbDAO" />
</property>
</bean>
<bean id="qsbAction" class="com.cmms.action.QsbAction">
<property name="dao">
<ref local="qsbDAO" />
</property>
</bean>
</beans>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/cmms?useUnicode=true&characterEncoding=utf-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!-- 配置Hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/cmms/bean/Users.hbm.xml</value>
<value>com/cmms/bean/Qsb.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- 配置事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 定义DAO -->
<bean id="userDAO" class="com.cmms.dao.UsersDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="qsbDAO" class="com.cmms.dao.QsbDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 定义DAO代理 -->
<bean id="UserDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="QsbDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="qsbDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- spring整合Struts2配置 -->
<bean id="loginAction" class="com.cmms.action.LoginAction">
<property name="dao"><!-- 依赖注入的dao的对象名称 -->
<ref local="userDAO" /><!-- 调用bean的id为users的dao层组建 -->
</property>
</bean>
<bean id="usersmanagementAction" class="com.cmms.action.UsersManagementAction">
<property name="dao">
<ref local="userDAO" />
</property>
</bean>
<bean id="openissureactionplanaction" class="com.cmms.action.OpenIssureActionPlanAction">
<property name="dao">
<ref local="qsbDAO" />
</property>
</bean>
<bean id="qsbAction" class="com.cmms.action.QsbAction">
<property name="dao">
<ref local="qsbDAO" />
</property>
</bean>
</beans>
哪里出问题了吗?