Hibernate无法检索值

时间:2013-07-09 05:42:51

标签: hibernate java-ee

我有以下类,需要对它们执行一个条件,但是hibernate找不到属性。

Class Car extends Vehicle
{
    String name;
    getter and setter of name;
}

Class Vehicle {
    Engine engine;

    @OneToOne(cascade = CascadeType.ALL)
    public Engine getEngine() {
     return engine;
    }

    setter goes here 
}

Class Engine {
   String name;
   getter and setter of name;

}

我的代码

    ....
    Criteria cre = session.createCriteria(Car.class,"car");
    cre.add(Restrictions.eq("engine.name", "314Full));
    return (Car) cre.list().get(0);
    ....

遇到以下错误

无法解析属性:engine.name of:com.myproject.car

1 个答案:

答案 0 :(得分:0)

尝试

session.createCriteria(Car.class,"car").createAlias("engine","engine");