如何在 HQL 中获取多对一映射数据

How to fetch Many To one mapping data in HQL

我在 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 查询。

试试这个:

list = session.createQuery("from Car c where c.admin = "+admin.getId()).list();