2

我有以下类,需要对它们执行条件,但休眠没有找到该属性。

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

4

1 回答 1

0

尝试

session.createCriteria(Car.class,"car").createAlias("engine","engine");
于 2013-07-09T05:54:43.810 回答