获取HQL而不是标准

时间:2013-05-30 08:37:01

标签: hibernate hql criteria

我有一个如下所示的标准,我在方法参数中传递id,如下所示

public List<abcObject> getabcObjects(String id) {
    Criteria query = session.createCriteria(abcObject.class);

    if(id!=null) {
        query.add(Restrictions.eq("ID", id));
    }

    List<abcObject> abcObjectsList = query.list();

    return abcObjectsList;
}

如下图所示ID列是从后端获取的,请你告诉我等价的HQL,因为我希望用HQL来获得相同的结果

1 个答案:

答案 0 :(得分:1)

HQL语句如下:

select abc from abcObject abc where abc.id = :id

及其利用率:

Integer id = 0; //this will change
String hql = "select abc from abcObject abc where abc.id = :id";
Query query = session.createQuery(hql);
query.setParameter("id", id);
List results = query.list();