用hql语句删除的时候执行dao层方法报这个错误,哪位大神帮我分析下错误原因,多谢

org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: java.util.ArrayList; nested exception is org.hibernate.MappingException: Unknown entity: java.util.ArrayList
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:683) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:837) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:833) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.sunyard.audit.model.modelplat.TranCodeDAO.delete(TranCodeDAO.java:41) ~[TranCodeDAO.class:na]
at com.sunyard.audit.model.modelplat.TranCodeDAO$$FastClassByCGLIB$$7fffcc57.invoke() [cglib-nodep-2.2.2.jar:na]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [cglib-nodep-2.2.2.jar:na]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.sunyard.audit.model.modelplat.TranCodeDAO$$EnhancerByCGLIB$$82df1988.delete() [cglib-nodep-2.2.2.jar:na]
at com.sunyard.audit.service.ModelSetService.isEmpty(ModelSetService.java:2729) [ModelSetService.class:na]
at com.sunyard.audit.service.ModelSetService$$FastClassByCGLIB$$9179a7b.invoke() [cglib-nodep-2.2.2.jar:na]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [cglib-nodep-2.2.2.jar:na]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.sunyard.audit.service.ModelSetService$$EnhancerByCGLIB$$edc70d4.isEmpty() [cglib-nodep-2.2.2.jar:na]
at com.sunyard.audit.struts.ModelSetAction.managerEntrySetting(ModelSetAction.java:686) [ModelSetAction.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_02]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_02]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_02]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_02]
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270) [struts.jar:1.2.9]
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187) [struts.jar:1.2.9]
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) [struts.jar:1.2.9]
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) [struts.jar:1.2.9]
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) [struts.jar:1.2.9]
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [struts.jar:1.2.9]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) [servlet-api.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
at com.sunyard.audit.filter.LoginFilter.doFilter(LoginFilter.java:80) [LoginFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
at com.sunyard.audit.filter.EncodingFilter.doFilter(EncodingFilter.java:43) [EncodingFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
at com.sunyard.audit.filter.EncodingFilter.doFilter(EncodingFilter.java:43) [EncodingFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
at com.sunyard.audit.filter.ResourceCacheFilter.doFilter(ResourceCacheFilter.java:125) [ResourceCacheFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:na]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:na]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) [catalina.jar:na]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:na]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:na]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) [catalina.jar:na]
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857) [tomcat-coyote.jar:na]
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565) [tomcat-coyote.jar:na]
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509) [tomcat-coyote.jar:na]
at java.lang.Thread.run(Thread.java:619) [na:1.6.0_02]
Caused by: org.hibernate.MappingException: Unknown entity: java.util.ArrayList
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514) ~[hibernate3.jar:na]
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1302) ~[hibernate3.jar:na]
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:59) ~[hibernate3.jar:na]
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:761) ~[hibernate3.jar:na]
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:739) ~[hibernate3.jar:na]
at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:843) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
... 58 common frames omitted
09:42:49 c.s.a.s.BaseAction ERROR - Unknown entity: java.util.ArrayList; nested exception is org.hibernate.MappingException: Unknown entity: java.util.ArrayList
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: java.util.ArrayList; nested exception is org.hibernate.MappingException: Unknown entity: java.util.ArrayList
Caused by: org.hibernate.MappingException: Unknown entity: java.util.ArrayList

5个回答

删除方法传的参数不对。getHibernateTemplate().delete() 方法,参数是要删除的实体对象。你应该把实体列表遍历再单个传入删除。

dao方法和调用都贴出来

baidu_28393753
SCNelson dao方法 public void delete(List<TranCode> trans){ log.debug("deleting TranCode instance"); try{ getHibernateTemplate().delete(trans); log.debug("delete successful"); }catch(RuntimeException re){ log.error("delete failed",re); throw re; } }
大约 4 年之前 回复

service层抽象方法
public void isEmpty(TranCode tc,String id);

service层抽象方法实现类,调用dao层delete方法
public void isEmpty(TranCode tc,String id){
    List<TranCode> trans = tranCodeDAO.findByModelId(id);
    if(trans.size()<=0){
        tranCodeDAO.save(tc);
    }else{
        tranCodeDAO.delete(trans);
        tranCodeDAO.save(tc);
    }
}

TranCode实体类
public class TranCode implements java.io.Serializable{

private String modelId;
private String code;
public String getModelId() {
    return modelId;
}
public void setModelId(String modelId) {
    this.modelId = modelId;
}
public String getCode() {
    return code;
}
public void setCode(String code) {
    this.code = code;
}
baidu_28393753
SCNelson 回复男哥: 我设置的双主键
大约 4 年之前 回复
jiaowonange8
男哥 把你的主键改成id试试
大约 4 年之前 回复

第一次见,删除直接传集合的!!!

        tranCodeDAO.delete(trans);       
        这段是几个意思,,改成这样:
        for(TranCode  tc:trans){
            tranCodeDAO.delete(tc);   
        }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问