from po.test为啥要写po呢?难道你的类不叫test吗?不用写package的

解决方案 »

  1.   

    from test a where a.name = sdf 试试
      

  2.   

    不用po.test
    改成test也是一样的
      

  3.   

    楼主试试这个:
    from test as t where t.name = 'sdf'
      

  4.   

    就从你的这句HQL来分析原因吧:
    "from po.test where test.name = sdf"问题之一:
    sdf是个字符串值,应该加单引号。不然Hibernate会把它作为类的属性看待,而你的类中是没有sdf这个属性的问题之二:
    from后直接写类名,不必加包名问题之三:
    test是类名,不能直接使用test.name(不能通过类来访问,就好像你不能通过类名去访问实例变量一样),请不要问为什么,记住这是HQL的语法要求就行了。
    那怎么办呢?通常会用别名的方式解决,比如
    from test as t where t.name = 'sdf'(别名就好像是test类的一个对象,通过对象就可以访问实例变量啦,哈哈)
    所以你也可以这样写:
    from test as test where test.name = 'sdf'(注意现在test.name中的test是别名了)当然,仅对一个类进行操作,也可以不借助于别名:
    from test where name = 'sdf'