UserActionForm uaf = (UserActionForm)form;
//用户标识
int userId = uaf.getId();
//角色标识
int roleId = uaf.getRoleId();
System.out.println("------------"+userId);
System.out.println("-------------"+roleId);
userManager.delUserRole(userId, roleId);
return mapping.findForward("pub_del_success");
我从页面接收userid 和roleid 我的打印语句能测试到 这两个值
但是执行这句删除语句错误,包 这种异常
java.lang.IllegalArgumentException: attempt to create delete event with null entity
at org.hibernate.event.DeleteEvent.<init>(DeleteEvent.java:24)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:848)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:842)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:838)
at com.edu.oa.managerImpl.UserManagerImpl.delUserRole(UserManagerImpl.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy5.delUserRole(Unknown Source)
at com.edu.oa.web.action.UserAction.delUserRole(UserAction.java:133)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.edu.oa.web.PagerFilter.doFilter(PagerFilter.java:29)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:866)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:716)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1498)
at java.lang.Thread.run(Thread.java:619)
我的删除语句是:
public void delUserRole(int userId, int roleId) {
getHibernateTemplate().delete(findUsersRoles(userId,roleId));
}
private UsersRoles findUsersRoles(int userId, int roleId){
return (UsersRoles)getSession().createQuery(
"select ur from UsersRoles ur where ur.role.id = ? and ur.user.id = ?")
.setParameter(0, userId)
.setParameter(1, roleId)
.uniqueResult();
}
我的映射文件时
user映射文件<hibernate-mapping>
<class table="t_user" name="com.edu.oa.model.User" >
<id name="id">
<generator class="native"/>
</id>
<property name="username" not-null="true" unique="true"/>
<property name="password" not-null="true"/>
<property name="createTime" update="false"/>
<property name="expireTime"/>
<many-to-one unique="true" name="person" />
</class>
</hibernate-mapping>
role映射文件
<hibernate-mapping>
<class table="t_role" name="com.edu.oa.model.Role">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
userrole映射文件
<hibernate-mapping>
<class table="t_usersRoles" name="com.edu.oa.model.UsersRoles" >
<id name="id">
<generator class="native"/>
</id>
<many-to-one name="role" />
<many-to-one name="user" />
<property name="orderNo"/>
</class>
</hibernate-mapping>
找到答案了是那的错
private UsersRoles findUsersRoles(int userId, int roleId){
return (UsersRoles)getSession().createQuery(
"select ur from UsersRoles ur where ur.role.id = ? and ur.user.id = ?")
.setParameter(0, userId)
.setParameter(1, roleId) 红色地方有顺序不一样, 教训啊!紧记
.uniqueResult();
}