HQL={select b from Body b,StoryName s where  b.storyName=s.storyId and s.storyId=3  and b.chapterId=(select  max(chapterId) from Body where b.storyName=s.storyId and s.storyId=3 )} 以上代码是用HQL执行过 
我把具体值改成?
调用find(HQL,aa【】)就报错java.util.ArrayList cannot be cast to com.entity.Body
新手没分呀

解决方案 »

  1.   

    只要hibernate配置正确,对应关系对应正确,进行子查询是没有没问题。我感觉你的实体对应关系应该配置错误了,好好检查一下吧。
      

  2.   

    调用find(HQL,aa【】)就报错java.util.ArrayList cannot be cast to com.entity.Body貌似 ArrayList 转换 实体 Body 出错。看看你取的aa【】(?)是不是有问题吧。
      

  3.   

    我查询代码写的多余了
    select b from Body b,Story s where  b.cheapterId=(select max(b.cheapterId) from Body b,Story s  where s.story=? ) 后来我无耻了点  我直接赋值 我就不用max了
    int[] aa=new int[2];
    int idd=13;
    id=3;
    aa[0]=id;
    aa[1]=idd;
    return (Body)this.getHibernateTemplate().find("select b from Body b,StoryName s where   s.storyId=?  and b.chapterId=?",aa);
    网页是用实体body点出2条属性值(不在关联之列)
     java.lang.NumberFormatException: null
      

  4.   


    我试过 List li=null;
    li.add();
    报错 java.lang.NumberFormatException: null