this.getHibernateTemplate().save() 死循环 10
Action:publicActionForwardadd(ActionMappingmapping,ActionFormform,HttpServletRequestr...
Action:
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeeForm employeeForm = (EmployeeForm) form;
Employee employee = new Employee();
BeanUtils.copyProperties(employee, employeeForm);
employee.setPassword(employee.getEmpNo());
employeeManager.addEmployee(employee);
Msg = "添加员工成功!";
request.setAttribute("Msg", Msg);
return mapping.findForward("add_success");
}
------------------------------------------------------------------------------
public void addEmployee(Employee employee) {
try {
this.getHibernateTemplate().save(employee);
}catch(Exception e) {
e.printStackTrace();
throw new AppException("jxc.employee.error.addEmployee");
}
}
-----------------------------------------------------------------------
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 哪些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.cczu.jxc.business.manager.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
<bean name="/emp" class="com.cczu.jxc.web.actions.EmployeeAction">
<property name="employeeManager" ref="employeeManager"/>
</bean>
<bean id="employeeManager" class="com.cczu.jxc.business.manager.EmployeeManagerImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
-----------------------------------------------
this.getHibernateTemplate().save() 死循环,无限主键自增插入数据 展开
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
EmployeeForm employeeForm = (EmployeeForm) form;
Employee employee = new Employee();
BeanUtils.copyProperties(employee, employeeForm);
employee.setPassword(employee.getEmpNo());
employeeManager.addEmployee(employee);
Msg = "添加员工成功!";
request.setAttribute("Msg", Msg);
return mapping.findForward("add_success");
}
------------------------------------------------------------------------------
public void addEmployee(Employee employee) {
try {
this.getHibernateTemplate().save(employee);
}catch(Exception e) {
e.printStackTrace();
throw new AppException("jxc.employee.error.addEmployee");
}
}
-----------------------------------------------------------------------
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 哪些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.cczu.jxc.business.manager.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
<bean name="/emp" class="com.cczu.jxc.web.actions.EmployeeAction">
<property name="employeeManager" ref="employeeManager"/>
</bean>
<bean id="employeeManager" class="com.cczu.jxc.business.manager.EmployeeManagerImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
-----------------------------------------------
this.getHibernateTemplate().save() 死循环,无限主键自增插入数据 展开
2个回答
展开全部
public void addEmployee(Employee employee) {
try {
this.getHibernateTemplate().save(employee);
}catch(Exception e) {
e.printStackTrace();
throw new AppException("jxc.employee.error.addEmployee");
}
}
将 this.getHibernateTemplate().save(employee);
改成super.getHibernateTemplate().save(employee);
try {
this.getHibernateTemplate().save(employee);
}catch(Exception e) {
e.printStackTrace();
throw new AppException("jxc.employee.error.addEmployee");
}
}
将 this.getHibernateTemplate().save(employee);
改成super.getHibernateTemplate().save(employee);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询