今天在使用hibernate查询的时候,遇到一个开始比较迷惑的问题。问题大概意思描述如下:
如数据表test,有test_name,home_addr等字段,对应的hbmh和pojo中,忘记新增属性home_addr。
开始使用如下hql: from TestModel as t where t.testName=? and t.homeAddr = ?
运行出错:提示没有对应的homeAddr属性。
把hql改成如下:  from TestModel as t where t.testName=? and home_addr=? 即可运行。
但如下hql:  from TestModel as t where t.test_name=? and home_addr=? 出错了
    from TestModel as t where testName=? and home_addr=? 出错了

结论如下:hql支持根据属性和物理字段的混排,属性可直接使用,或者用“pojo别名.属性”,但物理字段只能直接使用,不能使用“pojo别名.物理字段”。如果使用pojo别名,则不能直接使用属性,必须用“pojo别名.属性”。
呵呵,绕了半天,有点意思。