String hql = "select new fi.salesManagement.bean.PurchaseVo(f.inId as Id,f.ifoId as ifoId,i.UTime as time,f.ACurnum as count,f.inPrice as inprice) from PurchaseInStorageInfo f inner join PurchaseInStorage i with f.inId = i.inId and  f.delFlag = 0 and i.delFlag = 0 and f.AId = ? and f.sId = ?";
String hql = "select new fi.salesManagement.bean.PurchaseVo(f.inId as Id,f.ifoId as ifoId,i.UTime as time,f.ACurnum as count,f.inPrice as inprice) from PurchaseInStorageInfo f, PurchaseInStorage i where f.inId = i.inId";
List<PurchaseVo> PurchaseVoList = this.createQuery(getSession(), hql, values).list();
PurchaseVo定义和构造方法如下:        private Long inId;
private Long ifoId;
private Date UTime;
private Long ACurnum;
private BigDecimal inPrice; public PurchaseVo(Long inId, Long ifoId, Date uTime, Long aCurnum,
BigDecimal inPrice) {
super();
this.inId = inId;
this.ifoId = ifoId;
UTime = uTime;
ACurnum = aCurnum;
this.inPrice = inPrice;
}
但是当我执行this.createQuery(getSession(), hql, values).list()的时候就报空指针错误,到底这是那里出错了,高手指教

解决方案 »

  1.   

    哦,上面的HQL代码部分发错了应该是下面这样的
    String hql = "select new fi.salesManagement.bean.PurchaseVo(f.inId as Id,f.ifoId as ifoId,i.UTime as time,f.ACurnum as count,f.inPrice as inprice) from PurchaseInStorageInfo f inner join PurchaseInStorage i with f.inId = i.inId and  f.delFlag = 0 and i.delFlag = 0 and f.AId = ? and f.sId = ?";
            List<PurchaseVo> PurchaseVoList = this.createQuery(getSession(), hql, values).list();
      

  2.   

    上面的问题解决了,但是如果我的hql语句中含有聚合函数 如:select new fi.salesManagement.bean.PurchaseVo(f.ifoId as ifoId,i.UTime as time,avg(f.inPrice) as inprice) from PurchaseInStorageInfo f, PurchaseInStorage i group by f.ifoId,i.UTime那么我的动态构造的实例对象PurchaseVo改怎么写啊???高手指点
      

  3.   

    java.lang.NullPointerException
    hibernate.HiberNateDBO.QueryHBData.stdHQL(QueryHBData.java:57)
    action.Login.execute(Login.java:64)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:270)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs.我了也是单独的HQL语句执行正确 但是结合struts执行到此就提示HQL空指针异常 可是不知道啥意思 从网上找到资料说是list=query.list()问题 可是我不懂为什么会发生赋值等待的意思
      

  4.   

    这个问题我遇到过,经过反复思考加上查看源码,你的这个new函数会导致hibernate去查询对应类中的构造方法,那么参数的类型如何确定,就是从hibernate的查询结果返回值中确定,如果你的其中某一关联对象有可能为空但这条数据又会出现在结果集的时候Hibernate通过反射获取对应的构造方法的时候因为你缺少一个参数而无法反射出对应的方法,就报空指针异常了,