更新一列不起作用

时间:2015-07-23 20:47:49

标签: spring hibernate spring-mvc

我想更新数据库的一列。列名称为status,类型为Enum('waiting','accepted','rejected') 我想在点击链接时更新此列:

persist

Vacation.hbm.xml

<a href="requests/action?id=${vac.id}&a=accepted">Accept</a>
<a href="requests/action?id=${vac.id}&a=rejected">Reject</a>

控制器

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.terafast.tem.model">
    <class name="Vacation" table="vacations" dynamic-update="true">
        <id name="id" column="REQUEST_ID">
            <generator class="native" />
        </id>
        <property name="user" column="USER_ID" />
        <property name="reason" column="REASON" />
        <property name="duration" column="HOW_LONG" />
        <property name="status" column="STATUS" />
        <property name="start" type="date" column="START_DATE" />
        <property name="created" type="date" column="CREATED_AT" />
    </class>
</hibernate-mapping>

我可以成功获得这两个GET值。 (id,a)。我的VacationDAOImpl:

@RequestMapping(value = "/requests/action")
public String statuHandler(HttpServletRequest request, Model model) {
    int id = Integer.parseInt(request.getParameter("id"));
    String status = request.getParameter("a");
    vacationDao.actionStatus(id, status);

    return "redirect:/admin/requests";

servlet的context.xml中

@Override
@Transactional
public void actionStatus(int id, String action) {
    Session session = sessionFactory.openSession();
    Query q = session.createQuery("from Vacation where id = :reqid ");
    q.setParameter("reqid", id);
    Vacation vacation = (Vacation) q.list().get(0);

    vacation.setStatus(action);
    session.update(vacation);
}

我在this tutorial中看到了这种方法。 当我点击链接时,一切看起来都不错。但列值不会改变。有人可以解释这个问题吗?

0 个答案:

没有答案