Hibernate标准API equals方法

Hibernate标准API equals方法,hibernate,Hibernate,我已经使用hibernate反向工程来生成我的模型和Dao类 我正在使用hibernate标准API从数据库中检索值 criteria.add(Restrictions.eq( "propert1.propert2.StateId", 1)); 我得到以下异常 javax.faces.el.EvaluationException:org.hibernate.QueryException:无法解析com.packagename的属性:propert1.proper

我已经使用hibernate反向工程来生成我的模型和Dao类 我正在使用hibernate标准API从数据库中检索值

    criteria.add(Restrictions.eq(
            "propert1.propert2.StateId", 1));
我得到以下异常

javax.faces.el.EvaluationException:org.hibernate.QueryException:无法解析com.packagename的属性:propert1.propert2.StateId


有人知道为什么会发生这种情况吗?(创建条件的类有property1,而propert1的类有propert2)

定义别名应该做到这一点

criteria.createAlias("propert1","pr1")
    .createAlias("pr1.propert2","pr2")
    .add(Restrictions.eq("pr2.StateId", 1));
这对我有用

Criteria criteria = session
            .createCriteria(MyClass.class);
criteria = criteria.createCriteria("propert1").createCriteria("propert2").add(Restrictions.eq("stateId", 1));

首都“S”?按照惯例,JavaBean属性名称以小写字母开头(即
getName
=>属性名称为
name
)。是的,我在这里更改了它,但在我的类中,这些属性的名称是正确的,因为这些类是通过hibernate反向工程生成的,所以这不是问题,谢谢你的回复,我试过这样的方法:criteria=criteria.createCriteria(“propert1”).createCriteria(“propert2”).add(Restrictions.eq(“stateId”,1));这对我很有效。我也会用你的方式试试。@好奇:两种方法几乎完全相同。如果你真的很“好奇”,请参考和类似的内容)@好奇:而且,如果你用你的答案更新你的问题,你会帮助别人的!我已经尝试过你的方法,但是我得到了以下异常org.hibernate.QueryException:无法解析属性:stateId of:Myclass