急急急!HibernateTemplate的update锁数据表问题

michaelliuyang NQ 软件工程师  2011-07-22 11:30:56
我自己的action如果继承action类,去update表,就没有问题,事务可以正常提交。如果自己的action继承了dispatchAction,然后再去update,就产生了数据表被锁死的问题,数据也更新不成功,请教各个大侠这个问题是什么情况。
代码如下:

dao类
package com.dao;

import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.entity.Orders;

public class OrdersDao extends HibernateDaoSupport{

@SuppressWarnings("unchecked")
public List<Orders> getAllOrders(){
return this.getHibernateTemplate().find("from Orders as o");
}

public void update(Orders order){
this.getHibernateTemplate().update(order);
}

public void delete(int id) {

}

public Orders getOrderById(int id){
return this.getHibernateTemplate().get(Orders.class, id);
}
}
action类
package com.action;

import java.sql.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.entity.Orders;
import com.service.OrdersService;

@Transactional(propagation=Propagation.REQUIRED)
public class OrdersAction extends DispatchAction {
private OrdersService ordersService;

public OrdersService getOrdersService() {
return ordersService;
}

public void setOrdersService(OrdersService ordersService) {
this.ordersService = ordersService;
}

public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List<Orders> orders = this.ordersService.getOrders();
request.setAttribute("orders", orders);
return mapping.findForward("list");
}

public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Orders or = ordersService.getOrderById(1);
or.setCustName("yy1");
this.ordersService.updateUser(or);
return null;
}
}
配置文件
app.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="ordersDao" class="com.dao.OrdersDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="ordersService" class="com.service.OrdersService">
<property name="ordersDao" ref="ordersDao"></property>
</bean>

<bean name="/ordersAction" class="com.action.OrdersAction">
<property name="ordersService" ref="ordersService"></property>
</bean>
</beans>

struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/ordersAction" type="com.action.OrdersAction" scope="request" parameter="method">
<forward name="list" path="/ordersList.jsp"></forward>
<forward name="update" path="/orderAction.do?method=update"></forward>
</action>
</action-mappings>

<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>

<message-resources parameter="ApplicationResources" />
</struts-config>
...全文
156 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
michaelliuyang 2011-07-22
最后发现是事务得配到service层,不配到action,估计是dispatchaction对事务有影响,结贴!
回复
michaelliuyang 2011-07-22
qq 120121723
回复
michaelliuyang 2011-07-22
[Quote=引用 4 楼 zl3450341 的回复:]

把异常贴出来看看
[/Quote]
关键是没有异常,但是手动查看数据库,数据库就是锁死的问题,我这里有代码,qq发给你?
回复
把异常贴出来看看
回复
把事务去掉试试
回复
michaelliuyang 2011-07-22
[Quote=引用 1 楼 zl3450341 的回复:]

你把事务加上action层上的啊
[/Quote]
我把事务就算删了,也没有用,也一样锁死
回复
你把事务加上action层上的啊
回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.7w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2011-07-22 11:30
社区公告
暂无公告