spring - Update one column does not works -
i want update 1 column of database. column name status , type enum('waiting' , 'accepted' , 'rejected') want update column when click on link:
<a href="requests/action?id=${vac.id}&a=accepted">accept</a> <a href="requests/action?id=${vac.id}&a=rejected">reject</a>
vacation.hbm.xml
<?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>
controller
@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";
i can these 2 values. (id , a). vacationdaoimpl:
@override @transactional public void actionstatus(int id, string action) { session session = sessionfactory.opensession(); query q = session.createquery("from vacation id = :reqid "); q.setparameter("reqid", id); vacation vacation = (vacation) q.list().get(0); vacation.setstatus(action); session.update(vacation); }
servlet-context.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <!-- enables spring mvc @controller programming model --> <mvc:annotation-driven /> <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory --> <mvc:resources mapping="/resources/**" location="/resources/" /> <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory --> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/views/" /> <property name="suffix" value=".jsp" /> </bean> <context:component-scan base-package="com.terafast.tem" /> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean> <bean id="employeedao" class="com.terafast.tem.dao.employeedaoimpl"> <constructor-arg> <ref bean="sessionfactory" /> </constructor-arg> </bean> <bean id="vacationdoa" class="com.terafast.tem.dao.vacationdaoimpl"> <constructor-arg> <ref bean="sessionfactory" /> </constructor-arg> </bean> </beans>
i have seen approach in this tutorial. when click on links, looks good. column value not change. explain problem?
Comments
Post a Comment