我在Java中有两个对象
@Entity
public class Car {
@Id
private long id;
private int color;
@ManyToOne
private Admin admin;
//setter-getter
}
@Entity
Class Admin{
@Id
private int id;
private String name;
//setter-getter
}
和获取
Admin admin=(Admin) session.getAdmin("user");
....
tx = session.getTransaction();
tx.begin();
list = session.createQuery("from Car where admin="+admin.getId()).list();
tx.commit();
....
但我收到了错误。任何人都可以告诉HQL查询是什么。
答案 0 :(得分:1)
试试这个:
list = session.createQuery("from Car c where c.admin = "+admin.getId()).list();