attempt to create delete event with null entity

attempt to create delete event with null entity 分析及解决

 

srtuts,spring连续删除的问题
很明显 你删除了 一条不存在的记录  这种错误 可能是你ID传值有误  还有可能就是你重复提交 删了一次 第二次 接着删 肯定报错了 
 
1. 描述

删除一个对象后,按F5刷新 ,出现错误。MyEclispe控制台下异常显示:
java.lang.IllegalArgumentException: attempt to create delete event with null entity

并且浏览器地址还是指向那个被删除的对象。如删除id=30的实体后,浏览器地址为 http://122.204.85.183:8080/PKJava/delete.do?id=30

2. 分析
请参照:http://fengzi015.spaces.live.com/blog/cns!fc609e3f70f965cf!247.entry

返回查询结果部分的问题,也就是说,是:删除记录之后返回的记录集没有刷新。删除的实体在结果集中没有清除。在刷新页面时,将前一form提交的内容都作为hidden又全传了回来,且是不断累加的。

3. 解决方法
在转到新界面时,刷新界面。
只需要修改sttruts.xml中delete action的配置。在delete action的<forward />中加入一个参数redirect="true"。 redirect默认值是false。

 

 

 

======

4月7日
连续删除的问题
jsp:
 
<ec:table items="result"
       var="pres"
       filterable="false"
       imagePath="${pageContext.request.contextPath}/html/commons/ximages/*.gif"
       rowsDisplayed="10"
       action=""
       form="confTypeForm">
   <ec:row highlightRow="true">
    <ec:column property="typeId"
      headerStyle="text-align:center"
      title="<%=GetProperty.getProperties("conftype.id",getServletContext())%>" >
     <input name="ids_allbox" type="checkbox" value="${pres.typeId}">
     <a href="<%=ContextUtil.getCtxPath(request)%>/para/modifyconftype.do?id=${pres.typeId}">${pres.typeId}</a>
    </ec:column>
    <ec:column property="typeName" headerStyle="text-align:center"
      style="text-align:center"
      filterable="false"
      sortable="false"
      title="<%=GetProperty.getProperties("conftype.name",getServletContext())%>" />
    <ec:column property="comments" headerStyle="text-align:center"
      style="text-align:center"
      filterable="false"
      sortable="false"
      title="<%=GetProperty.getProperties("conftype.comments",getServletContext())%>" />
   </ec:row>
  </ec:table>
 
 
java:
Action:
 
String[] ids = request.getParameterValues("ids_allbox");
  if (ids != null) {  
   try {
    ParameterUtil.deleteConferenceType(ids);
   } catch (Exception e) {
    e.printStackTrace();
    return mapping.findForward("error");
   }
  }
  request.setAttribute("result", ParameterUtil.getAllConferenceType());
  return mapping.findForward("viewconftype");
 
 
java:
Util:
public static boolean deleteConferenceType(String[] ids) {
  ConferenceTypeDAO dao = ConferenceTypeDAO.getInstance();
  Transaction t = beginTransaction();
  try {
   dao.deleteConferenceType(ids);
   t.commit();
   return true;
  }catch (HibernateException he) {
   he.printStackTrace();
   t.rollback();
   return false;
  }finally{
   closeSession();
  }  
 }
 
 
java:
DAO:
 
public void deleteConferenceType(String[] confTypeIds) throws HibernateException {
  Session s = getSession();
  try {
   for (int i=0, l=confTypeIds.length; i<l; i++) {
    s.delete(s.get(TConferenceType.class, new Integer(confTypeIds[i])));
   }
  } catch (HibernateException ex) {
   errlog.error(ex);
   throw ex;
  }
 }
 
 
xml:
 
   <action path="/deleteconftype"
     type="com.kingstargroup.conference.action.DeleteConferenceTypeAction"
     name="confTypeForm"
     validate="false"
     scope="request"
     input="/html/conference/parameter/viewconftype.jsp">
    <forward name="viewconftype" path="/html/conference/parameter/viewconftype.jsp"></forward>
   </action>
 
 
errors:
 
Hibernate: select tconferenc0_.TYPE_ID as TYPE1_0_, tconferenc0_.TYPE_NAME as TYPE2_7_0_, tconferenc0_.COMMENTS as COMMENTS7_0_ from ykt_conf.T_CONFERENCE_TYPE tconferenc0_ where tconferenc0_.TYPE_ID=?
java.lang.IllegalArgumentException: attempt to create delete event with null entity
 at org.hibernate.event.DeleteEvent.<init>(DeleteEvent.java:25)
 at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:578)
 at com.kingstargroup.conference.dao.ConferenceTypeDAO.deleteConferenceType(ConferenceTypeDAO.java:35)
 at com.kingstargroup.conference.util.ParameterUtil.deleteConferenceType(ParameterUtil.java:252)
 at com.kingstargroup.conference.action.DeleteConferenceTypeAction.execute(DeleteConferenceTypeAction.java:29)
 at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
 at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
 at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:49)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
 at com.kingstargroup.conference.filter.SetEncodingFilter.doFilter(SetEncodingFilter.java:38)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
 at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
 at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
 at java.lang.Thread.run(Thread.java:534)

问题解决了!
问题是:eXtremeTable 在刷新页面时,将前一form提交的内容都作为hidden又全传了回来,且是不断累加的。
解决方法是:在转到新界面时,刷新界面,struts代码如下,注意着重部分:
<action path="/deleteconftype"
     type="com.kingstargroup.conference.action.parameter.DeleteConferenceTypeAction"
     scope="request"
     input="/html/conference/parameter/viewconftype.jsp">
    <forward name="viewconftype" path="/viewconftype.do" redirect="true" ></forward>
   </action>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值