我使用了hibernate逆向工程来生成我的模型和Dao类 我正在使用hibernate标准API来检索数据库中的值
criteria.add(Restrictions.eq(
"propert1.propert2.StateId", 1));
我收到以下异常
javax.faces.el.EvaluationException:org.hibernate.QueryException:无法解析属性:properties1.propert2.StateId:com.packagename。
有没有人知道为什么会发生这种情况。(创建条件的类具有property1,而类1具有属性2)
答案 0 :(得分:1)
定义别名应该这样做
criteria.createAlias("propert1","pr1")
.createAlias("pr1.propert2","pr2")
.add(Restrictions.eq("pr2.StateId", 1));
答案 1 :(得分:0)
这为我工作
Criteria criteria = session
.createCriteria(MyClass.class);
criteria = criteria.createCriteria("propert1").createCriteria("propert2").add(Restrictions.eq("stateId", 1));