问题描述
使用hibernate数据库查询除了fingALL()方法以外其他方法都出现以下报错很纠结啊以前不会啊Theserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionjava.lang.reflect.InvocationTargetExceptionsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)java.lang.reflect.Method.invoke(Method.java:597)com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept。。。。。省略一些rootcausejava.lang.NoSuchMethodError:antlr.collections.AST.getLine()Iorg.hibernate.hql.ast.HqlSqlWalker.generatePositionalParameter(HqlSqlWalker.java:896)org.hibernate.hql.antlr.HqlSqlBaseWalker.parameter(HqlSqlBaseWalker.java:4819)org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1373)org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243)org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3725)org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1864)org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:818)org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:604)org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)com.hwadeecrm.dao.CrmuserDAO.findByProperty(CrmuserDAO.java:141)com.hwadeecrm.dao.CrmuserDAO.findByAuthorityId(CrmuserDAO.java:155)com.hwadeecrm.serviceImpl.CrmuserServiceImpl.findByUserName(CrmuserServiceImpl.java:58)com.hwadeecrm.action.CrmuserAction.searchCrmuser(CrmuserAction.java:96)sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)java.lang.reflect.Method.invoke(Method.java:597)com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
解决方案
解决方案二:
最好吧HQL语句贴出来看看,光凭这个报错很难看出问题啊
解决方案三:
jar包冲突原因:项目里有这两个jar包产生了冲突所致:antlr-2.7.6.jar和anltr-2.7.2.jar。将anltr-2.7.2.jar包删除即可。
解决方案四:
publicListfindBySearchUserName(StringsearchString){log.debug("findingCrmuserinstancewithUserNamecontents:"+searchString);try{StringqueryString="fromCrmuserasmodelwheremodel.userNamelike:value";QueryqueryObject=getSession().createQuery(queryString);queryObject.setString("value","%"+searchString+"%");System.out.println("--------------d");returnqueryObject.list();}catch(RuntimeExceptionre){log.error("findbypropertynamefailed",re);throwre;}}这个自己写的System.out.println("--------------d");出不来就报这个错如果使用DAO里自带的方法如:(全都报错)publicListfindByProperty(StringpropertyName,Objectvalue){log.debug("findingCrmuserinstancewithproperty:"+propertyName+",value:"+value);try{StringqueryString="fromCrmuserasmodelwheremodel."+propertyName+"=?";QueryqueryObject=getSession().createQuery(queryString);queryObject.setParameter(0,value);returnqueryObject.list();}catch(RuntimeExceptionre){log.error("findbypropertynamefailed",re);throwre;}}publicListfindByWorkerId(ObjectworkerId){returnfindByProperty(WORKER_ID,workerId);}publicListfindByAuthorityId(ObjectauthorityId){returnfindByProperty(AUTHORITY_ID,authorityId);}publicListfindByUserName(ObjectuserName){returnfindByProperty(USER_NAME,userName);}只有findAll()和findById()方法可以正常运行
解决方案五:
是包的问题吗?我在运行的还有一个项目啊也是这样做的没有包冲突报错的问题啊
解决方案六:
StringqueryString="fromCrmuserasmodelwheremodel.userNamelike:value";貌似这句错了,模糊查询hql语句不是这样吧StringqueryString="fromCrmuserasmodelwheremodel.userNamelike'%"+value+"%'";
解决方案七:
十分感谢是Hibernate版本问题模糊查询格式改了就可用了可是DAO自带的方法依然用不了一调用就出错publicListfindByProperty(StringpropertyName,Objectvalue){log.debug("findingCrmuserinstancewithproperty:"+propertyName+",value:"+value);try{StringqueryString="fromCrmuserasmodelwheremodel."+propertyName+"=?";QueryqueryObject=getSession().createQuery(queryString);queryObject.setParameter(0,value);returnqueryObject.list();}catch(RuntimeExceptionre){log.error("findbypropertynamefailed",re);throwre;}}publicListfindByWorkerId(ObjectworkerId){returnfindByProperty(WORKER_ID,workerId);}publicListfindByAuthorityId(ObjectauthorityId){returnfindByProperty(AUTHORITY_ID,authorityId);}publicListfindByUserName(ObjectuserName){returnfindByProperty(USER_NAME,userName);}